Repository navigation
fix(openai): preserve instruction roles and tool call data - #442
Closed
Kiro-Durandal wants to merge 1 commit into
Closed
Kiro-Durandal wants to merge 1 commit into
Kiro-Durandal wants to merge 1 commit into
Conversation
Owner
|
已部分合并 |
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.
修复 Chat Completions → AGY 转换中的工具参数丢失、中途指令降级和部分内容遗漏,并明确报告下述未支持输入。
改动与原因
arguments(字符串/对象,缺失时默认空字符串),避免 Pydantic 忽略参数后将合法调用降级为{}。systemInstruction,避免中途指令被改为普通 user;共享函数仍处理 Anthropic 顶层 system。tool_choice使用相同规范化;支持 auto/none/required 及命名函数选择。检查名称冲突、无工具却 required、指定未声明工具及命名选择的类型错误,避免名称不匹配或未处理异常。contents只有 user/model,防止非法角色到达 AGY。兼容性取舍
三个离线复现示例:参数、指令、未支持内容
以下输入经过请求模型和转换器,比较字段或本地错误;不调用真实模型。示例使用
gemini-3.8-flash-high,实机请求应先确认部署实际提供的模型名。1. 工具参数丢失
{ "model": "gemini-3.8-flash-high", "messages": [ {"role": "user", "content": "查询 test 对应的值"}, {"role": "assistant", "tool_calls": [{ "id": "call_example", "type": "function", "function": {"name": "lookup", "arguments": "{\"key\":\"test\"}"} }]}, {"role": "tool", "tool_call_id": "call_example", "content": "{\"value\":\"OK\"}"} ] }原有请求模型丢掉 arguments,最终
functionCall.args = {};修改后为{"key":"test"}。2. 中途 developer 被降为 user
{ "model": "gemini-3.8-flash-high", "messages": [ {"role": "user", "content": "你好"}, {"role": "assistant", "content": "你好"}, {"role": "developer", "content": "请简短回答"}, {"role": "user", "content": "继续"} ] }3. 远程图片被静默遗漏
{ "model": "gemini-3.8-flash-high", "messages": [{"role": "user", "content": [ {"type": "text", "text": "描述这张图片"}, {"type": "image_url", "image_url": {"url": "https://example.com/image.png"}} ]}] }原有仅转发文本;修改后在发送前返回 HTTP 400:
{"detail":"Antigravity requires image_url content as a base64 image data URL"}远程图片 URL 可以是合法的 Chat Completions 输入,但当前转换器仅处理 Base64 图片 data URL;此处是明确报告限制。
验证
基线
731e81e11ea0c96d40fff59ac94b1a0bbffe1101,Windows / Python 3.12.14:15 项全部通过,覆盖上述字段转换、工具选择、既有历史容错、图片编码以及模拟路由的 400/422 和发送前拦截。两个核心测试切回原始上游后,在四个子场景中按预期失败;上述三份示例 JSON 也已直接提取并复核。
版本查询和 AGY 后端均模拟,无需密钥。Anthropic 只验证共享合并函数,未测完整 messages 路由;图片检查只验证数据转换,不验证视觉理解。最新完整贡献分支尚未重做真实 AGY 端到端测试,字段检查也不证明模型指令遵循效果提升。
Black 24.10.0 按仓库配置(行长 100、目标 Python 3.13)检查通过:新测试整文件、运行代码的修改范围(
--line-ranges);git diff --check通过。