diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index 0e806549d..89e1fb5d1 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -666,7 +666,7 @@ def oper_msg(message, if chosen_provider in reply_prefix: chatgpt_res = reply_prefix[chosen_provider] + chatgpt_res except BaseException as e: - gu.log(f"调用异常:{traceback.format_exc()}", gu.LEVEL_ERROR) + gu.log(f"调用异常:{traceback.format_exc()}", gu.LEVEL_ERROR, max_len=100000) gu.log("调用语言模型例程时出现异常。原因: "+str(e), gu.LEVEL_ERROR) send_message(platform, message, "调用语言模型例程时出现异常。原因: "+str(e), msg_ref=msg_ref, session_id=session_id) return diff --git a/model/provider/provider_openai_official.py b/model/provider/provider_openai_official.py index 7779b5bc4..f0c00a6ef 100644 --- a/model/provider/provider_openai_official.py +++ b/model/provider/provider_openai_official.py @@ -93,7 +93,8 @@ class ProviderOpenAIOfficial(Provider): def text_chat(self, prompt, session_id = None): if session_id is None: session_id = "unknown" - del self.session_dict["unknown"] + if "unknown" in self.session_dict: + del self.session_dict["unknown"] # 会话机制 if session_id not in self.session_dict: self.session_dict[session_id] = [] diff --git a/util/func_call.py b/util/func_call.py index fd90b125b..153752246 100644 --- a/util/func_call.py +++ b/util/func_call.py @@ -43,12 +43,12 @@ class FuncCall(): return json.dumps(_l, indent=intent, ensure_ascii=False) - def func_call(self, question, func_definition, is_task = False, tasks = None, taskindex = -1, is_summary = True): + def func_call(self, question, func_definition, is_task = False, tasks = None, taskindex = -1, is_summary = True, session_id = None): funccall_prompt = """ -我正在实现function call功能,该功能旨在让你变成给定的问题到给定的函数的解析器(这意味着你不是创造函数)。 -下面会给你提供可能会用到函数的相关信息,和一个问题,你需要将其转换成给定的函数调用。 -- 你的返回信息只含json,且严格仿照以下内容(不含注释): +我正实现function call功能,该功能旨在让你变成给定的问题到给定的函数的解析器(意味着你不是创造函数)。 +下面会给你提供可能用到的函数相关信息和一个问题,你需要将其转换成给定的函数调用。 +- 你的返回信息只含json,严格仿照以下内容(不含注释): ``` { "res": string // 如果没有找到对应的函数,那么你可以在这里正常输出内容。如果有,这里是空字符串。 @@ -95,7 +95,7 @@ class FuncCall(): _c = 0 while _c < 3: try: - res = self.provider.text_chat(prompt) + res = self.provider.text_chat(prompt, session_id) if res.find('```') != -1: res = res[res.find('```json') + 7: res.rfind('```')] gu.log("REVGPT func_call json result", bg=gu.BG_COLORS["green"], fg=gu.FG_COLORS["white"]) @@ -140,7 +140,7 @@ class FuncCall(): # 生成返回结果 after_prompt = """ -函数返回以下内容:"""+invoke_func_res+""" +有以下内容:"""+invoke_func_res+""" 请以AI助手的身份结合返回的内容对用户提问做详细全面的回答。 用户的提问是: ```""" + question + """``` @@ -157,7 +157,7 @@ class FuncCall(): _c = 0 while _c < 5: try: - res = self.provider.text_chat(after_prompt) + res = self.provider.text_chat(after_prompt, session_id) # 截取```之间的内容 gu.log("DEBUG BEGIN", bg=gu.BG_COLORS["yellow"], fg=gu.FG_COLORS["white"]) print(res) diff --git a/util/gplugin.py b/util/gplugin.py index 907629e73..64537ccbd 100644 --- a/util/gplugin.py +++ b/util/gplugin.py @@ -130,7 +130,7 @@ def web_search(question, provider, session_id): func_definition1 = new_func_call.func_dump() question1 = f"{question} \n(只能调用一个函数。)" try: - res1, has_func = new_func_call.func_call(question1, func_definition1, is_task=False, is_summary=False) + res1, has_func = new_func_call.func_call(question1, func_definition1, is_task=False, is_summary=False, session_id=session_id) except BaseException as e: res = provider.text_chat(question) + "\n(网页搜索失败, 此为默认回复)" return res @@ -138,7 +138,7 @@ def web_search(question, provider, session_id): has_func = True if has_func: provider.forget(session_id) - question3 = f"""请你回答`{question}`问题。\n以下是相关材料,请直接拿此材料针对问题进行总结回答,再给出参考链接。不要提到任何函数调用的信息。```\n{res1}\n```\n""" + question3 = f"""请你回答`{question}`问题。\n以下是相关材料,请直接拿此材料针对问题进行总结回答,再给参考链接, 参考链接首末有空格。不要提到任何函数调用的信息。```\n{res1}\n```\n""" print(question3) _c = 0 while _c < 5: @@ -153,7 +153,7 @@ def web_search(question, provider, session_id): raise e if "The message you submitted was too long" in str(e): res2 = res2[:int(len(res2) / 2)] - question3 = f"""请你回答`{question}`问题。\n以下是相关材料,请直接拿此材料针对问题进行回答,再给出参考链接。```\n{res1}\n{res2}\n```\n""" + question3 = f"""请回答`{question}`问题。\n以下是相关材料,请直接拿此材料针对问题进行回答,再给参考链接, 参考链接首末有空格。```\n{res1}\n{res2}\n```\n""" return res3 else: return res1 \ No newline at end of file