mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
refactor(config): rename model mapping fields from from/to to name/alias
This commit is contained in:
@@ -201,29 +201,29 @@ ws-auth: false
|
||||
# NOTE: Mappings do not apply to gemini-api-key, codex-api-key, claude-api-key, openai-compatibility, vertex-api-key, or ampcode.
|
||||
# oauth-model-mappings:
|
||||
# gemini-cli:
|
||||
# - from: "gemini-2.5-pro" # original model name under this channel
|
||||
# to: "gpt-5" # client-visible alias
|
||||
# - name: "gemini-2.5-pro" # original model name under this channel
|
||||
# alias: "g2.5p" # client-visible alias
|
||||
# vertex:
|
||||
# - from: "gemini-2.5-pro"
|
||||
# to: "gpt-5"
|
||||
# - name: "gemini-2.5-pro"
|
||||
# alias: "g2.5p"
|
||||
# aistudio:
|
||||
# - from: "gemini-2.5-pro"
|
||||
# to: "gpt-5"
|
||||
# - name: "gemini-2.5-pro"
|
||||
# alias: "g2.5p"
|
||||
# antigravity:
|
||||
# - from: "gemini-3-pro-preview"
|
||||
# to: "gpt-5"
|
||||
# - name: "gemini-3-pro-preview"
|
||||
# alias: "g3p"
|
||||
# claude:
|
||||
# - from: "claude-sonnet-4-5-20250929"
|
||||
# to: "gpt-5"
|
||||
# - name: "claude-sonnet-4-5-20250929"
|
||||
# alias: "cs4.5"
|
||||
# codex:
|
||||
# - from: "gpt-5"
|
||||
# to: "gemini-2.5-pro"
|
||||
# - name: "gpt-5"
|
||||
# alias: "g5"
|
||||
# qwen:
|
||||
# - from: "qwen3-coder-plus"
|
||||
# to: "gpt-5"
|
||||
# - name: "qwen3-coder-plus"
|
||||
# alias: "qwen-plus"
|
||||
# iflow:
|
||||
# - from: "glm-4.7"
|
||||
# to: "gpt-5"
|
||||
# - name: "glm-4.7"
|
||||
# alias: "glm-god"
|
||||
|
||||
# OAuth provider excluded models
|
||||
# oauth-excluded-models:
|
||||
|
||||
@@ -146,10 +146,10 @@ type RoutingConfig struct {
|
||||
}
|
||||
|
||||
// ModelNameMapping defines a model ID rename mapping for a specific channel.
|
||||
// It maps the original model name (From) to the client-visible alias (To).
|
||||
// It maps the original model name (Name) to the client-visible alias (Alias).
|
||||
type ModelNameMapping struct {
|
||||
From string `yaml:"from" json:"from"`
|
||||
To string `yaml:"to" json:"to"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Alias string `yaml:"alias" json:"alias"`
|
||||
}
|
||||
|
||||
// AmpModelMapping defines a model name mapping for Amp CLI requests.
|
||||
@@ -508,29 +508,29 @@ func (cfg *Config) SanitizeOAuthModelMappings() {
|
||||
if channel == "" || len(mappings) == 0 {
|
||||
continue
|
||||
}
|
||||
seenFrom := make(map[string]struct{}, len(mappings))
|
||||
seenTo := make(map[string]struct{}, len(mappings))
|
||||
seenName := make(map[string]struct{}, len(mappings))
|
||||
seenAlias := make(map[string]struct{}, len(mappings))
|
||||
clean := make([]ModelNameMapping, 0, len(mappings))
|
||||
for _, mapping := range mappings {
|
||||
from := strings.TrimSpace(mapping.From)
|
||||
to := strings.TrimSpace(mapping.To)
|
||||
if from == "" || to == "" {
|
||||
name := strings.TrimSpace(mapping.Name)
|
||||
alias := strings.TrimSpace(mapping.Alias)
|
||||
if name == "" || alias == "" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(from, to) {
|
||||
if strings.EqualFold(name, alias) {
|
||||
continue
|
||||
}
|
||||
fromKey := strings.ToLower(from)
|
||||
toKey := strings.ToLower(to)
|
||||
if _, ok := seenFrom[fromKey]; ok {
|
||||
nameKey := strings.ToLower(name)
|
||||
aliasKey := strings.ToLower(alias)
|
||||
if _, ok := seenName[nameKey]; ok {
|
||||
continue
|
||||
}
|
||||
if _, ok := seenTo[toKey]; ok {
|
||||
if _, ok := seenAlias[aliasKey]; ok {
|
||||
continue
|
||||
}
|
||||
seenFrom[fromKey] = struct{}{}
|
||||
seenTo[toKey] = struct{}{}
|
||||
clean = append(clean, ModelNameMapping{From: from, To: to})
|
||||
seenName[nameKey] = struct{}{}
|
||||
seenAlias[aliasKey] = struct{}{}
|
||||
clean = append(clean, ModelNameMapping{Name: name, Alias: alias})
|
||||
}
|
||||
if len(clean) > 0 {
|
||||
out[channel] = clean
|
||||
|
||||
@@ -26,19 +26,19 @@ func compileModelNameMappingTable(mappings map[string][]internalconfig.ModelName
|
||||
}
|
||||
rev := make(map[string]string, len(entries))
|
||||
for _, entry := range entries {
|
||||
from := strings.TrimSpace(entry.From)
|
||||
to := strings.TrimSpace(entry.To)
|
||||
if from == "" || to == "" {
|
||||
name := strings.TrimSpace(entry.Name)
|
||||
alias := strings.TrimSpace(entry.Alias)
|
||||
if name == "" || alias == "" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(from, to) {
|
||||
if strings.EqualFold(name, alias) {
|
||||
continue
|
||||
}
|
||||
aliasKey := strings.ToLower(to)
|
||||
aliasKey := strings.ToLower(alias)
|
||||
if _, exists := rev[aliasKey]; exists {
|
||||
continue
|
||||
}
|
||||
rev[aliasKey] = from
|
||||
rev[aliasKey] = name
|
||||
}
|
||||
if len(rev) > 0 {
|
||||
out.reverse[channel] = rev
|
||||
|
||||
@@ -1191,19 +1191,19 @@ func applyOAuthModelMappings(cfg *config.Config, provider, authKind string, mode
|
||||
}
|
||||
forward := make(map[string]string, len(mappings))
|
||||
for i := range mappings {
|
||||
from := strings.TrimSpace(mappings[i].From)
|
||||
to := strings.TrimSpace(mappings[i].To)
|
||||
if from == "" || to == "" {
|
||||
name := strings.TrimSpace(mappings[i].Name)
|
||||
alias := strings.TrimSpace(mappings[i].Alias)
|
||||
if name == "" || alias == "" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(from, to) {
|
||||
if strings.EqualFold(name, alias) {
|
||||
continue
|
||||
}
|
||||
key := strings.ToLower(from)
|
||||
key := strings.ToLower(name)
|
||||
if _, exists := forward[key]; exists {
|
||||
continue
|
||||
}
|
||||
forward[key] = to
|
||||
forward[key] = alias
|
||||
}
|
||||
if len(forward) == 0 {
|
||||
return models
|
||||
|
||||
Reference in New Issue
Block a user