Skip to content

Conversation

@longkeyy
Copy link
Contributor

@longkeyy longkeyy commented Aug 26, 2025

功能特性:

  1. 全面的模型别名映射系统 (relay/model/alias.go)
  2. 支持多渠道别名 (OpenRouter, Anthropic, Gemini, Groq)
  3. 能力注册自动创建标准名称和渠道名称的双重映射
  4. 请求处理中集成别名解析 (先别名解析,再模型映射)
  5. 计费系统支持别名模型的费率查找
  6. 完整的测试覆盖和性能优化

支持的模型映射示例:

  • gpt-4o → OpenRouter: openai/gpt-4o, OpenAI: gpt-4o
  • claude-3-sonnet → OpenRouter: anthropic/claude-3-sonnet, Anthropic: claude-3-sonnet-20240229
  • llama-3-8b-instruct → OpenRouter: meta-llama/llama-3-8b-instruct, Groq: llama3-8b-8192

close #2310

- 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).
Copilot AI review requested due to automatic review settings August 26, 2025 18:46
Copy link

Copilot AI left a 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
Copy link

Copilot AI Aug 26, 2025

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.

Suggested change
case 24: // OpenRouter
case channeltype.OpenRouter: // OpenRouter

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +210
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{}
}
}
Copy link

Copilot AI Aug 26, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +754 to +776
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{}
}
Copy link

Copilot AI Aug 26, 2025

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment on lines +121 to +142
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{}
}
}
Copy link

Copilot AI Aug 26, 2025

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.

Copilot uses AI. Check for mistakes.
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