Skip to content

Commit a02fa83

Browse files
AmbratolmAmbratolm
authored andcommitted
Fixed AI response char limit prob
1 parent 96cb31f commit a02fa83

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

utils/ai.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ActAi(BaseModel):
2222
api_key: NonEmptyStr
2323
instructions: NonEmptyStr | list[NonEmptyStr] | None = None
2424
model_name: str = Field(alias="model", default="gemini-2.0-flash")
25+
response_char_limit: int = 4000
2526

2627
_client: Client | None = None
2728
_config: GenerateContentConfig | None = None
@@ -52,7 +53,10 @@ async def prompt(self, text: str, file: ActFile | None = None) -> str | None:
5253
Part.from_bytes(data=file.data, mime_type=file.mime_type or "")
5354
)
5455
response = await chat.send_message(message, self._config)
55-
return response.text if response else None
56+
response_text = response.text if response else None
57+
if response_text and len(response_text) > self.response_char_limit:
58+
response_text = response_text[: (self.response_char_limit - 3)] + "..."
59+
return response_text
5660

5761
# ----------------------------------------------------------------------------------------------------
5862

0 commit comments

Comments
 (0)