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'