Skip to content

Commit 8eb7264

Browse files
committed
fix: Impose a history limit to avoid the token intake exploding
limit is 13 messages
1 parent 6f465d5 commit 8eb7264

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ex_app/lib/nc_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ChatWithNextcloud(BaseChatModel):
3737
tools: Sequence[
3838
Union[typing.Dict[str, Any], type, Callable, BaseTool]] = []
3939
TIMEOUT: int = 60 * 20 # 20 minutes
40+
MAX_MESSAGE_HISTORY: int = 13
4041

4142
def _generate(
4243
self,
@@ -52,6 +53,9 @@ def _generate(
5253
task_input['system_prompt'] = messages[0].content
5354
messages = messages[1:]
5455

56+
# Impose a history limit to avoid the token intake exploding
57+
messages = messages[-self.MAX_MESSAGE_HISTORY:]
58+
5559
task_input['input'] = ''
5660
task_input['tool_message'] = []
5761
task_input['tools'] = json.dumps(self.tools)

0 commit comments

Comments
 (0)