reorx/ai.py

18kb history file => crash in ai.py

Cyborgscode opened this issue · 4 comments

Issue:

Mär 27 14:59:06 eve python3[120317]: detected unhandled Python exception in '/usr/local/sbin/ai.py'
Mär 27 14:59:06 eve abrt-server[120321]: Executable '/usr/local/sbin/ai.py' doesn't belong to any package and ProcessUnpackaged is set to 'no'
Mär 27 14:59:06 eve abrt-server[120321]: 'post-create' on '/var/spool/abrt/Python3-2023-03-27-14:59:06-120317' exited with 1
Mär 27 14:59:06 eve.resellerdesktop.de abrt-server[120321]: Deleting problem directory '/var/spool/abrt/Python3-2023-03-27-14:59:06-120317'

as soon as i deleted the history file, it worked again.

I suggest to limit it to the last 10 entries.

reorx commented

Could you try replicating the error with ai.py and share the stdout/stderr? The log above doesn't seem to provide any indication of what went wrong.

the file was an intact json file. My guess is, the open.ai API did not want to get that much history and reacted with an unkown errorcode. as soon as it's reoccurring, you will know.

ai.py -c -w --history .cache/pva/history.json "was ist Laser-Difraktion?"
Traceback (most recent call last):
File "/usr/local/sbin/ai.py", line 501, in
main()
File "/usr/local/sbin/ai.py", line 131, in main
chat_once(session, pm, args.prompt)
File "/usr/local/sbin/ai.py", line 139, in chat_once
res_message = session.chat(user_message)
File "/usr/local/sbin/ai.py", line 370, in chat
res_message, data, messages = self.create_completion(params_override=params_override)
File "/usr/local/sbin/ai.py", line 404, in create_completion
raise RequestError(e.status, e.read().decode()) from None
main.RequestError: RequestError: 400, {
"error": {
"message": "This model's maximum context length is 4097 tokens. However, your messages resulted in 4114 tokens. Please reduce the length of the messages.",
"type": "invalid_request_error",
"param": "messages",
"code": "context_length_exceeded"
}
}

And roundabout, we hit this at 18k of history file :)

forgetting old entries raises the question how to judge, which parts can go, and which should be kept. I.e. If i told ChatGPT in the past, to i.e. keep short about it's answeres, that would be important, where as the height of the mount everest is not important.