Skip to content

Vertex Claude 开关 + 工具调用修复 - #2741

Closed
XTFG wants to merge 2 commits into
QuantumNous:mainfrom
XTFG:main
Closed

Vertex Claude 开关 + 工具调用修复#2741
XTFG wants to merge 2 commits into
QuantumNous:mainfrom
XTFG:main

Conversation

@XTFG

@XTFG XTFG commented Jan 25, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Added Vertex provider setting to route Claude model requests through Gemini, directing traffic to Google endpoints instead of Anthropic.
    • New toggle switch in channel settings to enable/disable Gemini conversion for Claude models.
  • Improvements

    • Enhanced handling of multiple tool calls in Claude streaming responses.

✏️ Tip: You can customize this high-level summary in your review settings.

lys788 and others added 2 commits December 19, 2025 00:23
添加可配置开关以控制 Vertex 渠道中 Claude 模型请求的处理方式:
- 开关关闭(默认):使用原生 Anthropic 端点和格式
- 开关开启:将 Claude 请求转换为 Gemini 格式并发送到 Google 端点

后端修改:
- dto/channel_settings.go: 添加 VertexClaudeToGemini 字段
- relay/channel/vertex/adaptor.go:
  - Init 方法根据开关设置 RequestMode
  - ConvertClaudeRequest 方法在开关开启时调用 Gemini 转换

前端修改:
- EditChannelModal.jsx: 添加开关 UI 控件和相关数据处理逻辑

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
修复 OpenAI 转 Claude 格式时,工具调用场景下可能出现的多个
content_block_start 事件和未正确关闭 content_block 的问题。

主要改动:

1. 添加工具使用状态跟踪
   - 在 ClaudeConvertInfo 中新增 ToolUseStarted map 字段
   - 记录每个 block index 的工具使用开始状态

2. 支持首块多工具调用处理
   - 将单个工具调用处理改为循环处理多个工具调用
   - 正确设置每个工具的 block index
   - 标记已开始的工具使用块

3. 避免重复发送 content_block_start
   - 在 delta 处理中检查 ToolUseStarted 状态
   - 只在未开始时发送 content_block_start 事件

4. 正确处理工具调用的结束
   - 新增 generateToolUseStopBlocks 函数
   - 按索引顺序关闭所有未关闭的工具使用块
   - 在 finish_reason、done 等多个位置根据消息类型正确调用

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR adds a feature flag VertexClaudeToGemini to enable routing Claude model requests through the Gemini adapter for Vertex channels. It includes a new control flow in the Vertex adaptor to conditionally delegate Claude requests, infrastructure updates to track tool-use blocks during Claude-to-OpenAI conversion, and UI controls to manage the setting in channel configuration.

Changes

Cohort / File(s) Summary
Vertex Channel Configuration
dto/channel_settings.go
Added VertexClaudeToGemini boolean field to ChannelOtherSettings to store the feature flag; minor formatting adjustment to existing VertexKeyType line.
Vertex Adaptor Routing Logic
relay/channel/vertex/adaptor.go
Implemented conditional routing in ConvertClaudeRequest: when VertexClaudeToGemini is enabled, Claude requests delegate to Gemini adaptor; in Init, model selection switches between RequestModeClaude and RequestModeGemini based on the flag for "claude"-prefixed upstream models.
Claude Conversion Infrastructure
relay/common/relay_info.go
Added ToolUseStarted map field to ClaudeConvertInfo to track which tool-use blocks have begun; initialized in GenRelayInfoClaude.
Tool-Use Block Batching
service/convert.go
Introduced generateToolUseStopBlocks() function to finalize multiple tool-use blocks; enhanced streaming tool-call handling to generate content_block_start and content_block_delta for each tool call with index computation; added sort package import.
Channel Settings UI
web/src/components/table/channels/modals/EditChannelModal.jsx
Added UI toggle for vertex_claude_to_gemini setting under Vertex (type 41); implemented parsing from and serialization to channel settings JSON to prevent top-level field leakage; includes descriptive text explaining Claude-to-Gemini format conversion.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion

Poem

🐰 Through flags and flows, the rabbit hops with glee,
Claude now dances with Gemini, you see!
Tool blocks batched in streaming grace,
Settings UI finds its place,
Routing routes where they should be! ✨

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@XTFG XTFG closed this Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants