added message size limit of 2000 characters (issue 822) (#880)

* added message size limit (issue 822)
This commit is contained in:
Ori Yonay
2023-01-21 22:37:42 +01:00
committed by GitHub
parent 128102e6f1
commit cec49614c2
4 changed files with 10 additions and 0 deletions
+1
View File
@@ -54,6 +54,7 @@ class PublicSettings(pydantic.BaseModel):
PROJECT_NAME: str
API_V1_STR: str
MESSAGE_SIZE_LIMIT: int
DEBUG_USE_SEED_DATA: bool
DEBUG_ALLOW_SELF_LABELING: bool
DEBUG_SKIP_EMBEDDING_COMPUTATION: bool
+1
View File
@@ -72,6 +72,7 @@ class Settings(BaseSettings):
DATABASE_MAX_TX_RETRY_COUNT: int = 3
RATE_LIMIT: bool = True
MESSAGE_SIZE_LIMIT: int = 2000
REDIS_HOST: str = "localhost"
REDIS_PORT: str = "6379"
+7
View File
@@ -465,6 +465,13 @@ class TreeManager:
f"Frontend reports text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}."
)
# ensure message size is below the predefined limit
if len(interaction.text) > settings.MESSAGE_SIZE_LIMIT:
logger.error(
f"Message size {len(interaction.text)=} exceeds size limit of {settings.MESSAGE_SIZE_LIMIT=}."
)
raise OasstError("Message size too long.", OasstErrorCode.TASK_MESSAGE_TOO_LONG)
# here we store the text reply in the database
message = pr.store_text_reply(
text=interaction.text,
@@ -37,6 +37,7 @@ class OasstErrorCode(IntEnum):
TASK_GENERATION_FAILED = 1005
TASK_REQUESTED_TYPE_NOT_AVAILABLE = 1006
TASK_AVAILABILITY_QUERY_FAILED = 1007
TASK_MESSAGE_TOO_LONG = 1008
# 2000-3000: prompt_repository
INVALID_FRONTEND_MESSAGE_ID = 2000