perf: openai模型超限时截断消息(0.75x)

This commit is contained in:
Soulter
2023-09-30 15:06:57 +08:00
parent b9e331ebd6
commit 33dcc4c152
+3 -1
View File
@@ -139,9 +139,11 @@ class ProviderOpenAIOfficial(Provider):
else:
break
elif 'maximum context length' in str(e):
gu.log("token超限, 清空对应缓存")
gu.log("token超限, 清空对应缓存,并进行消息0.75倍截断")
self.session_dict[session_id] = []
prompt = prompt[:int(len(prompt)*0.75)]
cache_data_list, new_record, req = self.wrap(prompt, session_id)
elif 'Limit: 3 / min. Please try again in 20s.' in str(e) or "OpenAI response error" in str(e):
time.sleep(30)
else: