修复 C 版本 OpenAI Chat 请求体转换并对齐工具调用语义#34
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更内容
修复 C 版本在
--provider openai/ OpenAI Chat Completions 接口下,请求体仍沿用 Claude 格式的问题。原来的行为是:
/chat/completionsconvert_to_openai()只是空壳,未真正参与请求构造这会导致:
tools没有按 OpenAItype=function结构发送system没有转成messages[].role=systemtool_use/ user 的tool_result也没有转成 OpenAI chat 语义具体修复
1. 实现 C 版 Claude -> OpenAI body conversion
在
c/transport.c中补全convert_to_openai(),对齐 bash / Rust / Go 的语义:system-> prepend 为 OpenAIsystemmessagetools-> OpenAI{"type":"function","function":...}tool_use->tool_callstool_result->role=toolthinking/output_config.effort-> OpenAIthinking+reasoning_effort2. 主请求路径接入转换
在
c/agent.c中:openai时再调用convert_to_openai()3. compact / summary 请求也接入转换
修复长会话 compact 时的 OpenAI 路径:
/chat/completionsconvert_to_openai()4. 对齐 OpenAI header 语义
修复一个顺手发现的对齐问题:
x-app: cli5. 补充回归测试
在
tests/test.sh中新增 OpenAI request body 检查:/last-requestrole=systemtools[].type=functionparametersinput_schema验证
已验证:
make build-c/bin/zsh -lc 'AGENT=./dist/cagent bash tests/test.sh 9904'结果:
125 passed, 0 failed