Skip to content

fix: vertex thinkingbudget in name - #1251

Closed
RedwindA wants to merge 2 commits into
QuantumNous:alphafrom
RedwindA:fix/vertex-budget-name
Closed

fix: vertex thinkingbudget in name#1251
RedwindA wants to merge 2 commits into
QuantumNous:alphafrom
RedwindA:fix/vertex-budget-name

Conversation

@RedwindA

@RedwindA RedwindA commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

之前适配的时候忘了移除vertex渠道发送的后缀

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of model name suffixes for more accurate model selection.
    • Enhanced error handling for unsupported request modes to improve reliability.

@coderabbitai

coderabbitai Bot commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The Init, GetRequestURL, and ConvertOpenAIRequest methods were refactored to replace multiple if-else statements with unified switch statements for handling request modes. The suffix trimming logic for UpstreamModelName was updated to prioritize splitting on the substring "-thinking-" before trimming suffixes. Error handling for unsupported request modes was added, including a special URL case for Claude in the "global" region.

Changes

File(s) Change Summary
relay/channel/vertex/adaptor.go Refactored control flow from if-else chains to switch statements in Init, GetRequestURL, and ConvertOpenAIRequest; updated suffix handling for UpstreamModelName in Gemini mode; added special case for Claude "global" region URL; added default error handling for unsupported request modes.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Adaptor

    Caller->>Adaptor: Init(UpstreamModelName)
    Adaptor->>Adaptor: switch on UpstreamModelName prefix/substring
    Adaptor-->>Caller: Set RequestMode or error

    Caller->>Adaptor: GetRequestURL(OriginModelName, UpstreamModelName)
    alt UpstreamModelName contains "-thinking-"
        Adaptor->>Adaptor: Split UpstreamModelName at "-thinking-"
        Adaptor->>Adaptor: Use first segment as UpstreamModelName
    else UpstreamModelName ends with "-thinking"
        Adaptor->>Adaptor: Trim "-thinking" suffix
    else UpstreamModelName ends with "-nothinking"
        Adaptor->>Adaptor: Trim "-nothinking" suffix
    end
    Adaptor->>Adaptor: switch on RequestMode
    alt RequestModeClaude and Region == "global"
        Adaptor->>Adaptor: Build special global Claude URL
    else
        Adaptor->>Adaptor: Build URL based on mode
    end
    Adaptor-->>Caller: Return URL or error

    Caller->>Adaptor: ConvertOpenAIRequest(request)
    Adaptor->>Adaptor: switch on RequestMode to convert request or return error
    Adaptor-->>Caller: Converted request or error
Loading

Possibly related PRs

Poem

🐇 Hopping through code with a switch so neat,
Trimming suffixes, making logic complete.
From thinking splits to modes that align,
Errors caught early, now all is fine!
Rabbits rejoice, the flow’s refined,
Clearer paths for the code we find! ✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 615b804 and 4866831.

📒 Files selected for processing (1)
  • relay/channel/vertex/adaptor.go (6 hunks)
🧰 Additional context used
🪛 golangci-lint (1.64.8)
relay/channel/vertex/adaptor.go

154-154: expected '}', found 'default'

(typecheck)

🔇 Additional comments (3)
relay/channel/vertex/adaptor.go (3)

67-74: LGTM: Clean refactor to switch statement

The refactor from if-else to switch statement improves readability while maintaining the same logic for setting RequestMode based on model name patterns.


89-96: LGTM: Correct thinking budget suffix handling

The updated logic correctly prioritizes splitting on "-thinking-" substring before checking for suffix removal. This addresses the PR objective of fixing the vertex thinkingbudget naming issue where the suffix wasn't properly removed.


173-194: LGTM: Clean switch statement refactor with improved error handling

The refactor from if-else to switch statement improves code structure and readability. The addition of explicit error handling for unsupported request modes in the default case is a good practice.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
relay/channel/vertex/adaptor.go (2)

86-94: Consider extracting the “thinking-suffix” trimming into a shared helper

relay/channel/gemini/adaptor.go and this file now share identical suffix-stripping logic.
Duplicating this code in multiple adaptors invites divergence and makes future fixes harder. A small utility (e.g. relay/common/modelname.TrimThinkingSuffix(...)) would centralise the behaviour and unit tests.

This refactor can be done separately but is strongly recommended.


86-87: Non-English inline comment

The codebase appears predominantly English; keeping comments consistent aids readability for all contributors.

- // 与relay/channel/gemini/adaptor.go 中的逻辑保持一致
+ // Keep logic consistent with relay/channel/gemini/adaptor.go
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba6b063 and 8825652.

📒 Files selected for processing (1)
  • relay/channel/vertex/adaptor.go (1 hunks)

Comment thread relay/channel/vertex/adaptor.go Outdated
@RedwindA RedwindA closed this Jun 20, 2025
@RedwindA RedwindA reopened this Jun 20, 2025
@RedwindA
RedwindA force-pushed the fix/vertex-budget-name branch from b1602c3 to 615b804 Compare June 20, 2025 08:31
@RedwindA RedwindA closed this Jun 20, 2025
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.

1 participant