Skip to content

feat: implement new handlers for relay processing - #1270

Merged
Calcium-Ion merged 1 commit into
alphafrom
refactor_model_mapping
Jun 20, 2025
Merged

feat: implement new handlers for relay processing#1270
Calcium-Ion merged 1 commit into
alphafrom
refactor_model_mapping

Conversation

@Calcium-Ion

@Calcium-Ion Calcium-Ion commented Jun 20, 2025

Copy link
Copy Markdown
Member

feat: implement new handlers for relay processing

  • Added new handlers: AudioHelper, ImageHelper, EmbeddingHelper, and ResponsesHelper to manage respective requests.
  • Updated ModelMappedHelper to accept request parameters for better model mapping.
  • Enhanced error handling and validation across new handlers to ensure robust request processing.
  • Introduced support for new relay formats in relay_info and updated relevant functions accordingly.

Summary by CodeRabbit

  • New Features

    • Added support for additional relay formats, including audio, image, rerank, and embedding, with improved handling for each type.
  • Refactor

    • Enhanced model mapping logic across various helper functions, streamlining how model names are updated and reducing redundant assignments.
    • Updated relay information generation to use format-specific functions, improving clarity and maintainability.
  • Bug Fixes

    • Improved consistency in model name handling for Gemini-related features, ensuring correct application of settings and budget configurations.

…es processing

- Added new handlers: AudioHelper, ImageHelper, EmbeddingHelper, and ResponsesHelper to manage respective requests.
- Updated ModelMappedHelper to accept request parameters for better model mapping.
- Enhanced error handling and validation across new handlers to ensure robust request processing.
- Introduced support for new relay formats in relay_info and updated relevant functions accordingly.
@coderabbitai

coderabbitai Bot commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change updates relay information handling and model mapping across several relay handler functions. It introduces specialized relay info generators for different formats, revises the ModelMappedHelper to accept and update request objects based on relay format, and standardizes usage of UpstreamModelName for model mapping and adapter logic.

Changes

File(s) Change Summary
relay/common/relay_info.go Adds new relay format constants and generator functions for audio, image, embedding, responses, rerank, gemini. Updates existing generators for explicit relay format tagging and streaming/usage flags.
relay/helper/model_mapped.go Updates ModelMappedHelper to accept a request parameter and set its Model field based on relay format.
relay/audio_handler.go
relay/claude_handler.go
relay/embedding_handler.go
relay/gemini_handler.go
relay/image_handler.go
relay/relay-text.go
relay/rerank_handler.go
relay/responses_handler.go
controller/channel-test.go
Updates calls to ModelMappedHelper to pass the request object; removes explicit model assignment after helper call.
relay/channel/gemini/adaptor.go
relay/channel/gemini/relay-gemini.go
Replaces use of OriginModelName with UpstreamModelName for model name logic in Gemini thinking adapter and budget handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Handler
    participant RelayInfoGen
    participant ModelMappedHelper

    Client->>Handler: Sends API request
    Handler->>RelayInfoGen: Generate relay info (format-specific)
    RelayInfoGen-->>Handler: Returns RelayInfo
    Handler->>ModelMappedHelper: Map model name (pass context, RelayInfo, request)
    ModelMappedHelper-->>Handler: Updates request.Model as needed
    Handler-->>Client: Processed response
Loading

Possibly related PRs

Poem

In the meadow, models hop and play,
Now mapped with care in a format array.
From audio to image, each relay is wise,
With helpers that nudge requests to the skies.
A rabbit’s delight, as code aligns—
Every model mapped, in tidy lines!
🐇✨


📜 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 b087b20 and d328689.

📒 Files selected for processing (13)
  • controller/channel-test.go (1 hunks)
  • relay/audio_handler.go (2 hunks)
  • relay/channel/gemini/adaptor.go (1 hunks)
  • relay/channel/gemini/relay-gemini.go (1 hunks)
  • relay/claude_handler.go (1 hunks)
  • relay/common/relay_info.go (3 hunks)
  • relay/embedding_handler.go (2 hunks)
  • relay/gemini_handler.go (2 hunks)
  • relay/helper/model_mapped.go (2 hunks)
  • relay/image_handler.go (1 hunks)
  • relay/relay-text.go (1 hunks)
  • relay/rerank_handler.go (1 hunks)
  • relay/responses_handler.go (1 hunks)
🔇 Additional comments (24)
relay/rerank_handler.go (1)

45-45: LGTM: ModelMappedHelper signature update is consistent with refactoring.

The addition of rerankRequest as the third parameter aligns with the broader refactoring to centralize model mapping logic within ModelMappedHelper. This eliminates the need for explicit model assignment in individual handlers.

relay/responses_handler.go (1)

66-66: LGTM: Consistent ModelMappedHelper signature update.

The addition of req parameter follows the consistent pattern across all handlers to centralize model mapping logic.

controller/channel-test.go (1)

93-93: LGTM: Appropriate handling of ModelMappedHelper in test context.

Passing nil as the third parameter is appropriate for the test context where there's no specific request object. Ensure that ModelMappedHelper handles nil request gracefully.

relay/audio_handler.go (2)

58-58: LGTM: Using specialized relay info generator for audio requests.

The switch to GenRelayInfoOpenAIAudio provides format-specific relay info generation, which is part of the broader enhancement to support multiple relay formats.


92-92: LGTM: Consistent ModelMappedHelper signature update for audio requests.

Adding audioRequest as the third parameter centralizes model mapping logic and maintains consistency with other handlers.

relay/image_handler.go (2)

105-105: LGTM: Using specialized relay info generator for image requests.

The switch to GenRelayInfoImage provides format-specific relay info generation, consistent with the pattern established for other request types.


113-113: LGTM: Consistent ModelMappedHelper signature update for image requests.

Adding imageRequest as the third parameter completes the consistent refactoring pattern across all handlers to centralize model mapping logic.

relay/claude_handler.go (1)

49-52: LGTM: Centralized model mapping logic.

The updated ModelMappedHelper call that includes the textRequest parameter is part of a systematic refactor to centralize model mapping logic. This eliminates the need for manual model field assignment in individual handlers and improves consistency.

relay/relay-text.go (1)

111-114: LGTM: Consistent with centralized model mapping refactor.

The updated ModelMappedHelper call follows the same pattern seen across other handlers, centralizing model mapping logic by passing the request object directly to the helper function.

relay/channel/gemini/relay-gemini.go (1)

102-102: LGTM: Standardized model name handling.

The change from info.OriginModelName to info.UpstreamModelName aligns with the broader refactor to standardize model name handling across the codebase. This ensures consistency in how model names are processed in the thinking adapter logic.

relay/channel/gemini/adaptor.go (1)

76-83: LGTM: Consistent model name standardization across Gemini components.

The changes from info.OriginModelName to info.UpstreamModelName in the thinking adapter logic ensure consistency with similar changes in relay/channel/gemini/relay-gemini.go. This standardization is essential for proper model name processing across all Gemini-related components.

relay/gemini_handler.go (2)

86-86: LGTM: Specialized relay info generation.

The change to use GenRelayInfoGemini instead of the generic GenRelayInfo introduces format-specific relay information handling, which improves modularity and allows for Gemini-specific configurations.


100-103: LGTM: Centralized model mapping consistent with other handlers.

The updated ModelMappedHelper call that includes the req parameter follows the same beneficial pattern implemented across other relay handlers, centralizing model mapping logic and reducing code duplication.

relay/embedding_handler.go (2)

36-36: LGTM: Using specialized relay info generator for embeddings.

The change to use GenRelayInfoEmbedding instead of the generic GenRelayInfo aligns with the new format-specific relay info generation pattern and properly sets the relay format for embedding requests.


50-50: LGTM: Centralized model mapping with request object.

The updated call to ModelMappedHelper now includes the embeddingRequest parameter, allowing the helper to handle model field updates internally. This eliminates the need for manual model assignment and centralizes the model mapping logic.

relay/helper/model_mapped.go (3)

14-14: LGTM: Enhanced function signature for centralized model mapping.

The addition of the request any parameter allows the function to update model fields directly in request objects, centralizing model mapping logic that was previously scattered across handlers.


55-90: LGTM: Comprehensive relay format handling with proper type assertions.

The implementation correctly handles different relay formats with appropriate type assertions and includes proper error handling. The default case gracefully handles GeneralOpenAIRequest and logs warnings for unsupported types.


57-59: Verify intentional empty implementation for Gemini format.

The RelayFormatGemini case contains only a comment with no implementation. Please confirm this is intentional if Gemini requests don't require model field updates.

#!/bin/bash
# Description: Check if Gemini requests have model fields that need updating
# Expected: Find Gemini request structures and verify if they have Model fields

# Search for Gemini request structures
ast-grep --pattern 'type $_ struct {
    $$$
    Model $_
    $$$
}'

# Also search for any Gemini-related model assignments in handlers
rg -A 3 -B 3 "gemini.*[Mm]odel.*=" --type go
relay/common/relay_info.go (6)

37-44: LGTM: Well-defined relay format constants.

The new relay format constants follow a consistent naming convention and provide clear categorization for different request types. This enables proper format-specific handling throughout the relay system.


159-163: LGTM: Consistent OpenAI Audio relay info generator.

The function follows the established pattern of calling GenRelayInfo and setting the appropriate RelayFormat. The implementation is clean and consistent with other specialized generators.


165-169: LGTM: Proper embedding relay info generator.

The function correctly sets the RelayFormatEmbedding format, enabling format-specific handling in the model mapping logic.


200-205: LGTM: Gemini relay info generator with usage optimization.

The function properly sets the Gemini format and disables usage inclusion (ShouldIncludeUsage = false), which is appropriate for Gemini's API characteristics.


207-211: LGTM: Image relay info generator follows pattern.

The function correctly implements the standard pattern for specialized relay info generation, setting the appropriate format for image requests.


174-176: LGTM: Responses format configuration with streaming disabled.

The updates correctly set the relay format and disable streaming support (SupportStreamOptions = false), which aligns with the responses API characteristics.

✨ 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.

@Calcium-Ion
Calcium-Ion merged commit 11792ba into alpha Jun 20, 2025
@Calcium-Ion
Calcium-Ion deleted the refactor_model_mapping branch July 12, 2025 04:11
@coderabbitai coderabbitai Bot mentioned this pull request Oct 13, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Nov 3, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Feb 28, 2026
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…apping

feat: implement new handlers for relay processing
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