From f9dde30a24806f4d94a68627d4cea4e5165725dd Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:38:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=9E=81=E7=AB=AF=E6=83=85=E5=86=B5=E9=80=A0=E6=88=90=E7=9A=84?= =?UTF-8?q?Index=E6=BA=A2=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index c88c5896f..c555a4ad6 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -247,7 +247,6 @@ async def oper_msg(message, at=False): chatgpt_res, current_usage_tokens = await get_chatGPT_response(cache_prompt) except (PromptExceededError) as e: print("出现token超限, 清空对应缓存") - # 超过4097tokens错误,清空缓存 session_dict[session_id] = [] cache_data_list = [] @@ -265,6 +264,8 @@ async def oper_msg(message, at=False): cache_list = session_dict[session_id] index = 0 while t > max_tokens: + if index >= len(cache_list): + break t -= int(cache_list[index]['single_tokens']) index += 1 session_dict[session_id] = cache_list[index:]