From dd8d9f568050a71b6f10432cfce5038faef3b39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Mon, 27 Oct 2025 21:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=20tool=5Fcall=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi_app.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fastapi_app.py b/fastapi_app.py index e8c7bba..2c11b42 100644 --- a/fastapi_app.py +++ b/fastapi_app.py @@ -42,6 +42,7 @@ from modified_assistant import update_agent_llm from task_queue.manager import queue_manager from task_queue.integration_tasks import process_files_async, cleanup_project_async from task_queue.task_status import task_status_store +import re os.environ["TOKENIZERS_PARALLELISM"] = "false" @@ -56,13 +57,24 @@ def get_content_from_messages(messages: List[dict], tool_response: bool = True) ANSWER_S = '[ANSWER]' for msg in messages: + if msg['role'] == ASSISTANT: if msg.get('reasoning_content'): assert isinstance(msg['reasoning_content'], str), 'Now only supports text messages' content.append(f'{THOUGHT_S}\n{msg["reasoning_content"]}') if msg.get('content'): assert isinstance(msg['content'], str), 'Now only supports text messages' - content.append(f'{ANSWER_S}\n{msg["content"]}') + # 过滤掉流式输出中的不完整 tool_call 文本 + content_text = msg["content"] + + # 使用正则表达式替换不完整的 tool_call 模式为空字符串 + + # 匹配并替换不完整的 tool_call 模式 + content_text = re.sub(r'