feat(translator): align OpenAI/Gemini/Claude protocol conversion and streaming behavior#1835
feat(translator): align OpenAI/Gemini/Claude protocol conversion and streaming behavior#1835Hsiangpo wants to merge 1 commit intorouter-for-me:mainfrom
Conversation
…streaming behavior
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the compatibility layer for various large language model providers, specifically OpenAI, Gemini, and Claude. The core objective is to ensure that requests and responses are translated with high fidelity, preserving data types, structures, and semantic meaning across different API protocols. This includes robust handling of complex fields like tool calls, image data, and multi-candidate outputs, leading to a more reliable and consistent experience when interacting with diverse LLM services through the proxy. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
此 PR 引入了广泛的修复和增强功能,以对齐 OpenAI、Gemini 和 Claude 之间的协议转换。这些更改是广泛的,涵盖了参数映射、多候选者支持以及工具调用和图像 URL 的数据保真度。为所有修复的路径添加全面的回归测试是一个很好的实践,显著提高了翻译器的鲁棒性。新的文档文件也是一个有价值的补充。
我发现了一些问题。一个是在文档文件名和标题中可能存在一个拼写错误。另一个是 sdk/translator/registry.go 文件中一个更关键的问题,其中检查响应转换器是否存在的逻辑似乎不正确,并可能导致错误。
| @@ -0,0 +1,146 @@ | |||
| # 2026-03-05 OpenAI 兼容层协议对齐修复记录 | |||
luispater
left a comment
There was a problem hiding this comment.
Thanks for the protocol-alignment work — the overall direction looks good, and the added regression coverage improves confidence in the request/response mapping changes.
That said, I found three blocking issues before this can be merged. Aside from these blocking items, the rest of the changes look reasonable to me.
Blocking findings:
- Blocking:
Gemini CLI -> OpenAIstreaming tracks tool-call indices globally instead of per choice. Ininternal/translator/gemini-cli/openai/chat-completions/gemini-cli_openai_response.go,FunctionIndexis shared across the whole stream, so if two candidates each emit their first function call, the second candidate getstool_calls[0].index = 1instead of0. OpenAI-compatible clients treat tool-call indices as scoped to a single choice, so this breaks reconstruction of multi-choice tool-call streams. - Blocking:
OpenAI -> Geministreaming also shares tool-call accumulation across choices. Ininternal/translator/openai/gemini/openai_gemini_response.go,ToolCallsAccumulatoris keyed only bytoolIndex, not by(choiceIndex, toolIndex). If two choices both emittool_calls[0], the later choice overwrites the earlier one. When a finish chunk arrives, the accumulated tool call is flushed into the wrong candidate and the shared accumulator is cleared, so the other candidate loses its tool call entirely. - Blocking: the PR introduces new Chinese comments, which violates the repository convention that code comments must be in English only. I noticed this in
internal/translator/openai/gemini/openai_gemini_request.go:67andinternal/translator/openai/claude/openai_claude_request.go:41. Please convert all newly added comments to English for consistency with the rest of the codebase.
Test plan:
go test ./internal/translator/...go test ./sdk/api/handlers/openai/...go test ./internal/runtime/executor/... -run "OpenAI|compat|Translator"- plus local repros for both multi-candidate streaming tool-call cases described above
Suggested follow-up:
- Please make the streaming tool-call state choice-aware in both directions.
- Please add regression tests for multi-candidate + tool-call streaming, not just multi-candidate text output.
- Please convert all newly added non-English comments to English.
Summary
docs/protocol/2026-03-05-openai-compat-alignment.mdVerification