mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
fix: 修复reset可能引起的bug
This commit is contained in:
@@ -327,7 +327,7 @@ class Session:
|
|||||||
json.dumps(self.prompt), json.dumps(self.default_prompt), json.dumps(self.token_counts))
|
json.dumps(self.prompt), json.dumps(self.default_prompt), json.dumps(self.token_counts))
|
||||||
|
|
||||||
# 重置session
|
# 重置session
|
||||||
def reset(self, explicit: bool = False, expired: bool = False, schedule_new: bool = True, use_prompt: str = None):
|
def reset(self, explicit: bool = False, expired: bool = False, schedule_new: bool = True, use_prompt: str = None, persist: bool = False):
|
||||||
if self.prompt:
|
if self.prompt:
|
||||||
self.persistence()
|
self.persistence()
|
||||||
if explicit:
|
if explicit:
|
||||||
@@ -345,7 +345,7 @@ class Session:
|
|||||||
if expired:
|
if expired:
|
||||||
pkg.utils.context.get_database_manager().set_session_expired(self.name, self.create_timestamp)
|
pkg.utils.context.get_database_manager().set_session_expired(self.name, self.create_timestamp)
|
||||||
|
|
||||||
if use_prompt:
|
if not persist: # 不要求保持default prompt
|
||||||
self.default_prompt = self.get_default_prompt(use_prompt)
|
self.default_prompt = self.get_default_prompt(use_prompt)
|
||||||
self.prompt = []
|
self.prompt = []
|
||||||
self.token_counts = []
|
self.token_counts = []
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str,
|
|||||||
"[bot]err:RateLimitError,请重试或联系作者,或等待修复")
|
"[bot]err:RateLimitError,请重试或联系作者,或等待修复")
|
||||||
except openai.error.InvalidRequestError as e:
|
except openai.error.InvalidRequestError as e:
|
||||||
if config.auto_reset and "This model's maximum context length is" in str(e):
|
if config.auto_reset and "This model's maximum context length is" in str(e):
|
||||||
session.reset()
|
session.reset(persist=True)
|
||||||
reply = [tips_custom.session_auto_reset_message]
|
reply = [tips_custom.session_auto_reset_message]
|
||||||
else:
|
else:
|
||||||
reply = handle_exception("{}API调用参数错误:{}\n".format(
|
reply = handle_exception("{}API调用参数错误:{}\n".format(
|
||||||
|
|||||||
Reference in New Issue
Block a user