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)
|
user_ma = re.match(user_re, message.user)
|
||||||
if chan_ma and user_ma:
|
if chan_ma and user_ma:
|
||||||
self.history.append({"role": "user", "content": str(message)})
|
self.history.append({"role": "user", "content": str(message)})
|
||||||
self.history = self.history[-limit:]
|
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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -119,6 +123,7 @@ class AIResponder(object):
|
|||||||
return answer, limit
|
return answer, limit
|
||||||
except openai.error.InvalidRequestError as err:
|
except openai.error.InvalidRequestError as err:
|
||||||
if 'maximum context length is' in str(err) and limit > 4:
|
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
|
limit -= 1
|
||||||
return None, limit
|
return None, limit
|
||||||
raise err
|
raise err
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user