Skip to content

Commit

Permalink
fix: avoid possible dead loop when discarding
Browse files Browse the repository at this point in the history
  • Loading branch information
lanvent committed Mar 26, 2023
1 parent 2b87f42 commit 9d875ae
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bot/chatgpt/chat_gpt_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,13 @@ def discard_exceed_conversation(self, session, max_tokens, total_tokens):
session.pop(1)
elif len(session) == 2 and session[1]["role"] == "assistant":
session.pop(1)
break
elif len(session) == 2 and session[1]["role"] == "user":
logger.warn("user message exceed max_tokens. total_tokens={}".format(dec_tokens))
break
else:
logger.debug("max_tokens={}, total_tokens={}, len(sessions)={}".format(max_tokens, dec_tokens, len(session)))
break
try:
cur_tokens = num_tokens_from_messages(session, self.model)
dec_tokens = cur_tokens
Expand Down

0 comments on commit 9d875ae

Please sign in to comment.