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