Skip to content

Commit

Permalink
fix: 在 OpenAI token 超出限制后丢弃历史会话(#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Mar 26, 2023
1 parent c00f454 commit fee700c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion robot/AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ def chat(self, texts, parsed):
respond = response.choices[0].text
logger.info(f"openai response: {respond}")
return respond

except self.openai.error.InvalidRequestError:
logger.warning("token超出长度限制,丢弃历史会话")
self.context = []
self.chat(texts, parsed)
except Exception:
logger.critical(
"openai robot failed to response for %r", msg, exc_info=True
Expand Down

0 comments on commit fee700c

Please sign in to comment.