-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat: 实现模型别名系统,支持跨渠道统一模型名称 #2311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add comprehensive model alias mapping system in relay/model/alias.go - Support standard model names (gpt-4o, claude-3-sonnet) across different channels - Modify AddAbilities() to create aliases for both standard and channel-specific names - Update text processing to resolve aliases before channel-specific mapping - Enhance billing system to support alias-based model ratio lookup - Add comprehensive tests for alias resolution and reverse mapping - Support major providers: OpenRouter, Anthropic, Gemini, Groq This allows users to use consistent model names (e.g., 'gpt-4o') regardless of channel provider, with automatic mapping to channel-specific names (e.g., 'openai/gpt-4o' for OpenRouter).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a comprehensive model alias system that allows mapping between standard model names and channel-specific model names across multiple AI service providers. The system provides bidirectional mapping capabilities and integrates alias resolution into the request processing pipeline.
Key changes:
- Core alias mapping system with support for OpenRouter, Anthropic, Gemini, and Groq channels
- Integration of alias resolution in request processing (before existing model mapping)
- Enhanced billing system to support alias-based rate lookups
- Automatic ability registration for both standard and channel-specific model names
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| relay/model/alias.go | Core alias mapping system with thread-safe operations and comprehensive model mappings |
| relay/model/alias_test.go | Complete test suite covering all alias functionality with benchmarks |
| relay/controller/text.go | Integration of alias resolution in text request processing |
| relay/controller/helper.go | Helper functions for lightweight alias resolution to avoid circular imports |
| relay/billing/ratio/model.go | Enhanced billing system to support alias-based model rate lookups |
| model/ability.go | Automatic expansion of model abilities to include standard names for channel-specific models |
Comments suppressed due to low confidence (2)
relay/controller/helper.go:1
- Magic numbers are used for channel types instead of constants from the channeltype package. This makes the code harder to maintain and understand. Consider using channeltype.OpenRouter, channeltype.Anthropic, etc.
package controller
relay/billing/ratio/model.go:1
- Magic numbers are used for channel types instead of constants from the channeltype package. This makes the code harder to maintain and understand. Consider using channeltype.OpenRouter, channeltype.Anthropic, etc.
package ratio
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // This is a lightweight version to avoid importing the full alias module | ||
| func getModelAliasesForChannelType(channelType int) map[string]string { | ||
| switch channelType { | ||
| case 24: // OpenRouter |
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers are used for channel types instead of constants from the channeltype package. This makes the code harder to maintain and understand. Consider using channeltype.OpenRouter, etc.
| case 24: // OpenRouter | |
| case channeltype.OpenRouter: // OpenRouter |
| func getChannelModelAliases(channelType int) map[string]string { | ||
| switch channelType { | ||
| case 24: // OpenRouter | ||
| return map[string]string{ | ||
| "gpt-4o": "openai/gpt-4o", | ||
| "gpt-4o-mini": "openai/gpt-4o-mini", | ||
| "gpt-4": "openai/gpt-4", | ||
| "gpt-4-turbo": "openai/gpt-4-turbo", | ||
| "gpt-3.5-turbo": "openai/gpt-3.5-turbo", | ||
| "gpt-3.5-turbo-0125": "openai/gpt-3.5-turbo-0125", | ||
| "o1": "openai/o1", | ||
| "o1-mini": "openai/o1-mini", | ||
| "o1-preview": "openai/o1-preview", | ||
| "claude-3-haiku": "anthropic/claude-3-haiku", | ||
| "claude-3-sonnet": "anthropic/claude-3-sonnet", | ||
| "claude-3-opus": "anthropic/claude-3-opus", | ||
| "claude-3.5-sonnet": "anthropic/claude-3.5-sonnet", | ||
| "claude-3.5-haiku": "anthropic/claude-3.5-haiku", | ||
| } | ||
| case 18: // Anthropic | ||
| return map[string]string{ | ||
| "claude-3-haiku": "claude-3-haiku-20240307", | ||
| "claude-3-sonnet": "claude-3-sonnet-20240229", | ||
| "claude-3-opus": "claude-3-opus-20240229", | ||
| "claude-3.5-sonnet": "claude-3-5-sonnet-20241022", | ||
| "claude-3.5-haiku": "claude-3-5-haiku-20241022", | ||
| } | ||
| case 28: // Gemini | ||
| return map[string]string{ | ||
| "gemini-pro": "gemini-pro", | ||
| "gemini-pro-1.5": "gemini-1.5-pro-latest", | ||
| "gemini-flash-1.5": "gemini-1.5-flash-latest", | ||
| } | ||
| case 33: // Groq | ||
| return map[string]string{ | ||
| "llama-3-8b-instruct": "llama3-8b-8192", | ||
| "llama-3-70b-instruct": "llama3-70b-8192", | ||
| "llama-3.1-8b-instruct": "llama-3.1-8b-instant", | ||
| "llama-3.1-70b-instruct": "llama-3.1-70b-versatile", | ||
| } | ||
| default: | ||
| return map[string]string{} | ||
| } | ||
| } |
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function duplicates the alias mappings that already exist in relay/model/alias.go. This creates a maintenance burden where aliases need to be updated in multiple places. Consider refactoring to use a single source of truth for alias mappings.
| switch channelType { | ||
| case 24: // OpenRouter | ||
| return map[string]string{ | ||
| "gpt-4o": "openai/gpt-4o", | ||
| "gpt-4o-mini": "openai/gpt-4o-mini", | ||
| "gpt-4": "openai/gpt-4", | ||
| "gpt-4-turbo": "openai/gpt-4-turbo", | ||
| "gpt-3.5-turbo": "openai/gpt-3.5-turbo", | ||
| "claude-3-haiku": "anthropic/claude-3-haiku", | ||
| "claude-3-sonnet": "anthropic/claude-3-sonnet", | ||
| "claude-3-opus": "anthropic/claude-3-opus", | ||
| "claude-3.5-sonnet": "anthropic/claude-3.5-sonnet", | ||
| } | ||
| case 18: // Anthropic | ||
| return map[string]string{ | ||
| "claude-3-haiku": "claude-3-haiku-20240307", | ||
| "claude-3-sonnet": "claude-3-sonnet-20240229", | ||
| "claude-3-opus": "claude-3-opus-20240229", | ||
| "claude-3.5-sonnet": "claude-3-5-sonnet-20241022", | ||
| } | ||
| default: | ||
| return map[string]string{} | ||
| } |
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function duplicates the alias mappings that already exist in relay/model/alias.go. This creates a maintenance burden where aliases need to be updated in multiple places. Consider refactoring to use a single source of truth for alias mappings.
| switch channelType { | |
| case 24: // OpenRouter | |
| return map[string]string{ | |
| "gpt-4o": "openai/gpt-4o", | |
| "gpt-4o-mini": "openai/gpt-4o-mini", | |
| "gpt-4": "openai/gpt-4", | |
| "gpt-4-turbo": "openai/gpt-4-turbo", | |
| "gpt-3.5-turbo": "openai/gpt-3.5-turbo", | |
| "claude-3-haiku": "anthropic/claude-3-haiku", | |
| "claude-3-sonnet": "anthropic/claude-3-sonnet", | |
| "claude-3-opus": "anthropic/claude-3-opus", | |
| "claude-3.5-sonnet": "anthropic/claude-3.5-sonnet", | |
| } | |
| case 18: // Anthropic | |
| return map[string]string{ | |
| "claude-3-haiku": "claude-3-haiku-20240307", | |
| "claude-3-sonnet": "claude-3-sonnet-20240229", | |
| "claude-3-opus": "claude-3-opus-20240229", | |
| "claude-3.5-sonnet": "claude-3-5-sonnet-20241022", | |
| } | |
| default: | |
| return map[string]string{} | |
| } | |
| // Use the alias mapping from relay/model/alias.go as the single source of truth | |
| return model.GetAliasMap(channelType) |
| func getModelAliasesForChannelType(channelType int) map[string]string { | ||
| switch channelType { | ||
| case 24: // OpenRouter | ||
| return map[string]string{ | ||
| "gpt-4o": "openai/gpt-4o", | ||
| "gpt-4o-mini": "openai/gpt-4o-mini", | ||
| "gpt-4": "openai/gpt-4", | ||
| "gpt-4-turbo": "openai/gpt-4-turbo", | ||
| "gpt-3.5-turbo": "openai/gpt-3.5-turbo", | ||
| "o1": "openai/o1", | ||
| "o1-mini": "openai/o1-mini", | ||
| "o1-preview": "openai/o1-preview", | ||
| "claude-3-haiku": "anthropic/claude-3-haiku", | ||
| "claude-3-sonnet": "anthropic/claude-3-sonnet", | ||
| "claude-3-opus": "anthropic/claude-3-opus", | ||
| "claude-3.5-sonnet": "anthropic/claude-3.5-sonnet", | ||
| "claude-3.5-haiku": "anthropic/claude-3.5-haiku", | ||
| } | ||
| default: | ||
| return map[string]string{} | ||
| } | ||
| } |
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function duplicates the alias mappings that already exist in relay/model/alias.go. This creates a maintenance burden where aliases need to be updated in multiple places. Consider refactoring to use a single source of truth for alias mappings.
功能特性:
支持的模型映射示例:
close #2310