From b9a983f8e0555641f94b6b4aef4ac85f6c45ee46 Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Mon, 7 Apr 2025 17:45:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E8=AE=B0,=20=E4=B8=8D=E8=AF=BB=E5=8F=96=E5=85=A5?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process_stage/method/llm_request.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index 674a7fd79..987e82570 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -58,12 +58,16 @@ class LLMRequestSubStage(Stage): if event.get_extra("provider_request"): req = event.get_extra("provider_request") - assert isinstance(req, ProviderRequest), ( - "provider_request 必须是 ProviderRequest 类型。" - ) + assert isinstance( + req, ProviderRequest + ), "provider_request 必须是 ProviderRequest 类型。" if req.conversation: - req.contexts = json.loads(req.conversation.history) + all_contexts = json.loads(req.conversation.history) + # 对函数工具调用做过滤 + req.contexts = [ + msg for msg in all_contexts if "_tool_call_history" not in msg + ] else: req = ProviderRequest(prompt="", image_urls=[]) if self.provider_wake_prefix: @@ -312,9 +316,12 @@ class LLMRequestSubStage(Stage): contexts = req.contexts contexts.append(await req.assemble_context()) - # tool calls result + # 记录并标记函数调用结果 if req.tool_calls_result: - contexts.extend(req.tool_calls_result.to_openai_messages()) + tool_calls_messages = req.tool_calls_result.to_openai_messages() + for message in tool_calls_messages: + message["_tool_call_history"] = True + contexts.extend(tool_calls_messages) contexts.append( {"role": "assistant", "content": llm_response.completion_text}