fix: 修复流式工具调用解析并更新标签格式
主要变更:
- 将工具调用标签从 {} 改为 <invoke></invoke>,避免与 JSON 括号冲突
- 修复流式请求未解析工具调用的问题,现在返回 OpenAI 格式的 tool_calls
- 从 SSE 响应中正确提取 content 并解析工具调用
- 更新提示词格式以使用新标签
- 更新所有相关测试用例
问题修复:
- 流式请求现在正确返回 OpenAI 格式的 tool_calls
- 标签冲突导致的解析失败问题已解决
- 所有单元测试通过 (20/20)
- API 完全兼容 OpenAI REST API tools 字段行为
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,10 +22,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Constants for tool call parsing
|
||||
# Using XML-style tags for clarity and better compatibility with JSON
|
||||
# LLM should emit:<tool_call>{"name": "...", "arguments": {...}}</tool_call>
|
||||
TOOL_CALL_START_TAG = "{"
|
||||
TOOL_CALL_END_TAG = "}"
|
||||
# Using XML-style tags to avoid confusion with JSON braces
|
||||
# LLM should emit: <tool_call>{"name": "...", "arguments": {...}}</tool_call>
|
||||
TOOL_CALL_START_TAG = "<invoke>"
|
||||
TOOL_CALL_END_TAG = "</invoke>"
|
||||
|
||||
|
||||
class ToolCallParseError(Exception):
|
||||
|
||||
Reference in New Issue
Block a user