Save history on short patch.
This commit is contained in:
parent
2cd66b55ee
commit
2ee2b092d6
@ -101,7 +101,11 @@ class AIResponder(object):
|
||||
user_ma = re.match(user_re, message.user)
|
||||
if chan_ma and user_ma:
|
||||
self.history.append({"role": "user", "content": str(message)})
|
||||
if len(self.history) > limit:
|
||||
self.history = self.history[-limit:]
|
||||
if self.history_file is not None:
|
||||
with open(self.history_file, 'wb') as fd:
|
||||
pickle.dump(self.history, fd)
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -119,6 +123,7 @@ class AIResponder(object):
|
||||
return answer, limit
|
||||
except openai.error.InvalidRequestError as err:
|
||||
if 'maximum context length is' in str(err) and limit > 4:
|
||||
logging.warning(f"context length exceeded, reduce the limit {limit}: {str(err)}")
|
||||
limit -= 1
|
||||
return None, limit
|
||||
raise err
|
||||
|
||||
Loading…
Reference in New Issue
Block a user