Browse Source

fix: avoid possible dead loop when discarding

master
lanvent 1 year ago
parent
commit
3d428ee844
1 changed files with 4 additions and 0 deletions
  1. +4
    -0
      bot/chatgpt/chat_gpt_bot.py

+ 4
- 0
bot/chatgpt/chat_gpt_bot.py View File

@@ -232,9 +232,13 @@ class SessionManager(object):
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


Loading…
Cancel
Save