mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor(config): rename model blacklist fields to excluded models
This commit is contained in:
@@ -62,7 +62,7 @@ ws-auth: false
|
||||
# headers:
|
||||
# X-Custom-Header: "custom-value"
|
||||
# proxy-url: "socks5://proxy.example.com:1080"
|
||||
# model-blacklist:
|
||||
# excluded-models:
|
||||
# - "gemini-2.0-pro-exp" # exclude specific models from this provider
|
||||
# - api-key: "AIzaSy...02"
|
||||
|
||||
@@ -78,7 +78,7 @@ ws-auth: false
|
||||
# headers:
|
||||
# X-Custom-Header: "custom-value"
|
||||
# proxy-url: "socks5://proxy.example.com:1080" # optional: per-key proxy override
|
||||
# model-blacklist:
|
||||
# excluded-models:
|
||||
# - "gpt-5" # exclude specific models from this provider
|
||||
|
||||
# Claude API keys
|
||||
@@ -92,7 +92,7 @@ ws-auth: false
|
||||
# models:
|
||||
# - name: "claude-3-5-sonnet-20241022" # upstream model name
|
||||
# alias: "claude-sonnet-latest" # client alias mapped to the upstream model
|
||||
# model-blacklist:
|
||||
# excluded-models:
|
||||
# - "claude-3-5-sonnet-20241022" # exclude specific models from this provider
|
||||
|
||||
# OpenAI compatibility providers
|
||||
@@ -128,8 +128,8 @@ ws-auth: false
|
||||
# params: # JSON path (gjson/sjson syntax) -> value
|
||||
# "reasoning.effort": "high"
|
||||
|
||||
# OAuth provider model blacklist
|
||||
#oauth-model-blacklist:
|
||||
# OAuth provider excluded models
|
||||
#oauth-excluded-models:
|
||||
# gemini-cli:
|
||||
# - "gemini-3-pro-preview"
|
||||
# vertex:
|
||||
|
||||
@@ -84,8 +84,8 @@ type Config struct {
|
||||
// Payload defines default and override rules for provider payload parameters.
|
||||
Payload PayloadConfig `yaml:"payload" json:"payload"`
|
||||
|
||||
// OAuthModelBlacklist defines per-provider global model blacklists applied to OAuth/file-backed auth entries.
|
||||
OAuthModelBlacklist map[string][]string `yaml:"oauth-model-blacklist,omitempty" json:"oauth-model-blacklist,omitempty"`
|
||||
// OAuthExcludedModels defines per-provider global model exclusions applied to OAuth/file-backed auth entries.
|
||||
OAuthExcludedModels map[string][]string `yaml:"oauth-excluded-models,omitempty" json:"oauth-excluded-models,omitempty"`
|
||||
}
|
||||
|
||||
// TLSConfig holds HTTPS server settings.
|
||||
@@ -161,8 +161,8 @@ type ClaudeKey struct {
|
||||
// Headers optionally adds extra HTTP headers for requests sent with this key.
|
||||
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
|
||||
|
||||
// ModelBlacklist lists model IDs that should be excluded for this provider.
|
||||
ModelBlacklist []string `yaml:"model-blacklist,omitempty" json:"model-blacklist,omitempty"`
|
||||
// ExcludedModels lists model IDs that should be excluded for this provider.
|
||||
ExcludedModels []string `yaml:"excluded-models,omitempty" json:"excluded-models,omitempty"`
|
||||
}
|
||||
|
||||
// ClaudeModel describes a mapping between an alias and the actual upstream model name.
|
||||
@@ -190,8 +190,8 @@ type CodexKey struct {
|
||||
// Headers optionally adds extra HTTP headers for requests sent with this key.
|
||||
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
|
||||
|
||||
// ModelBlacklist lists model IDs that should be excluded for this provider.
|
||||
ModelBlacklist []string `yaml:"model-blacklist,omitempty" json:"model-blacklist,omitempty"`
|
||||
// ExcludedModels lists model IDs that should be excluded for this provider.
|
||||
ExcludedModels []string `yaml:"excluded-models,omitempty" json:"excluded-models,omitempty"`
|
||||
}
|
||||
|
||||
// GeminiKey represents the configuration for a Gemini API key,
|
||||
@@ -209,8 +209,8 @@ type GeminiKey struct {
|
||||
// Headers optionally adds extra HTTP headers for requests sent with this key.
|
||||
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
|
||||
|
||||
// ModelBlacklist lists model IDs that should be excluded for this provider.
|
||||
ModelBlacklist []string `yaml:"model-blacklist,omitempty" json:"model-blacklist,omitempty"`
|
||||
// ExcludedModels lists model IDs that should be excluded for this provider.
|
||||
ExcludedModels []string `yaml:"excluded-models,omitempty" json:"excluded-models,omitempty"`
|
||||
}
|
||||
|
||||
// OpenAICompatibility represents the configuration for OpenAI API compatibility
|
||||
|
||||
@@ -509,12 +509,12 @@ func computeClaudeModelsHash(models []config.ClaudeModel) string {
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func computeModelBlacklistHash(blacklist []string) string {
|
||||
if len(blacklist) == 0 {
|
||||
func computeExcludedModelsHash(excluded []string) string {
|
||||
if len(excluded) == 0 {
|
||||
return ""
|
||||
}
|
||||
normalized := make([]string, 0, len(blacklist))
|
||||
for _, entry := range blacklist {
|
||||
normalized := make([]string, 0, len(excluded))
|
||||
for _, entry := range excluded {
|
||||
if trimmed := strings.TrimSpace(entry); trimmed != "" {
|
||||
normalized = append(normalized, strings.ToLower(trimmed))
|
||||
}
|
||||
@@ -531,14 +531,14 @@ func computeModelBlacklistHash(blacklist []string) string {
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
type modelBlacklistSummary struct {
|
||||
type excludedModelsSummary struct {
|
||||
hash string
|
||||
count int
|
||||
}
|
||||
|
||||
func summarizeModelBlacklist(list []string) modelBlacklistSummary {
|
||||
func summarizeExcludedModels(list []string) excludedModelsSummary {
|
||||
if len(list) == 0 {
|
||||
return modelBlacklistSummary{}
|
||||
return excludedModelsSummary{}
|
||||
}
|
||||
seen := make(map[string]struct{}, len(list))
|
||||
normalized := make([]string, 0, len(list))
|
||||
@@ -552,30 +552,30 @@ func summarizeModelBlacklist(list []string) modelBlacklistSummary {
|
||||
}
|
||||
}
|
||||
sort.Strings(normalized)
|
||||
return modelBlacklistSummary{
|
||||
hash: computeModelBlacklistHash(normalized),
|
||||
return excludedModelsSummary{
|
||||
hash: computeExcludedModelsHash(normalized),
|
||||
count: len(normalized),
|
||||
}
|
||||
}
|
||||
|
||||
func summarizeOAuthBlacklistMap(entries map[string][]string) map[string]modelBlacklistSummary {
|
||||
func summarizeOAuthExcludedModels(entries map[string][]string) map[string]excludedModelsSummary {
|
||||
if len(entries) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make(map[string]modelBlacklistSummary, len(entries))
|
||||
out := make(map[string]excludedModelsSummary, len(entries))
|
||||
for k, v := range entries {
|
||||
key := strings.ToLower(strings.TrimSpace(k))
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
out[key] = summarizeModelBlacklist(v)
|
||||
out[key] = summarizeExcludedModels(v)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func diffOAuthBlacklistChanges(oldMap, newMap map[string][]string) ([]string, []string) {
|
||||
oldSummary := summarizeOAuthBlacklistMap(oldMap)
|
||||
newSummary := summarizeOAuthBlacklistMap(newMap)
|
||||
func diffOAuthExcludedModelChanges(oldMap, newMap map[string][]string) ([]string, []string) {
|
||||
oldSummary := summarizeOAuthExcludedModels(oldMap)
|
||||
newSummary := summarizeOAuthExcludedModels(newMap)
|
||||
keys := make(map[string]struct{}, len(oldSummary)+len(newSummary))
|
||||
for k := range oldSummary {
|
||||
keys[k] = struct{}{}
|
||||
@@ -590,13 +590,13 @@ func diffOAuthBlacklistChanges(oldMap, newMap map[string][]string) ([]string, []
|
||||
newInfo, okNew := newSummary[key]
|
||||
switch {
|
||||
case okOld && !okNew:
|
||||
changes = append(changes, fmt.Sprintf("oauth-model-blacklist[%s]: removed", key))
|
||||
changes = append(changes, fmt.Sprintf("oauth-excluded-models[%s]: removed", key))
|
||||
affected = append(affected, key)
|
||||
case !okOld && okNew:
|
||||
changes = append(changes, fmt.Sprintf("oauth-model-blacklist[%s]: added (%d entries)", key, newInfo.count))
|
||||
changes = append(changes, fmt.Sprintf("oauth-excluded-models[%s]: added (%d entries)", key, newInfo.count))
|
||||
affected = append(affected, key)
|
||||
case okOld && okNew && oldInfo.hash != newInfo.hash:
|
||||
changes = append(changes, fmt.Sprintf("oauth-model-blacklist[%s]: updated (%d -> %d entries)", key, oldInfo.count, newInfo.count))
|
||||
changes = append(changes, fmt.Sprintf("oauth-excluded-models[%s]: updated (%d -> %d entries)", key, oldInfo.count, newInfo.count))
|
||||
affected = append(affected, key)
|
||||
}
|
||||
}
|
||||
@@ -605,7 +605,7 @@ func diffOAuthBlacklistChanges(oldMap, newMap map[string][]string) ([]string, []
|
||||
return changes, affected
|
||||
}
|
||||
|
||||
func applyAuthModelBlacklistMeta(auth *coreauth.Auth, cfg *config.Config, perKey []string, authKind string) {
|
||||
func applyAuthExcludedModelsMeta(auth *coreauth.Auth, cfg *config.Config, perKey []string, authKind string) {
|
||||
if auth == nil || cfg == nil {
|
||||
return
|
||||
}
|
||||
@@ -624,21 +624,21 @@ func applyAuthModelBlacklistMeta(auth *coreauth.Auth, cfg *config.Config, perKey
|
||||
}
|
||||
if authKindKey == "apikey" {
|
||||
add(perKey)
|
||||
} else if cfg.OAuthModelBlacklist != nil {
|
||||
} else if cfg.OAuthExcludedModels != nil {
|
||||
providerKey := strings.ToLower(strings.TrimSpace(auth.Provider))
|
||||
add(cfg.OAuthModelBlacklist[providerKey])
|
||||
add(cfg.OAuthExcludedModels[providerKey])
|
||||
}
|
||||
combined := make([]string, 0, len(seen))
|
||||
for k := range seen {
|
||||
combined = append(combined, k)
|
||||
}
|
||||
sort.Strings(combined)
|
||||
hash := computeModelBlacklistHash(combined)
|
||||
hash := computeExcludedModelsHash(combined)
|
||||
if auth.Attributes == nil {
|
||||
auth.Attributes = make(map[string]string)
|
||||
}
|
||||
if hash != "" {
|
||||
auth.Attributes["model_blacklist_hash"] = hash
|
||||
auth.Attributes["excluded_models_hash"] = hash
|
||||
}
|
||||
if authKind != "" {
|
||||
auth.Attributes["auth_kind"] = authKind
|
||||
@@ -831,7 +831,7 @@ func (w *Watcher) reloadConfig() bool {
|
||||
|
||||
var affectedOAuthProviders []string
|
||||
if oldConfig != nil {
|
||||
_, affectedOAuthProviders = diffOAuthBlacklistChanges(oldConfig.OAuthModelBlacklist, newConfig.OAuthModelBlacklist)
|
||||
_, affectedOAuthProviders = diffOAuthExcludedModelChanges(oldConfig.OAuthExcludedModels, newConfig.OAuthExcludedModels)
|
||||
}
|
||||
|
||||
// Always apply the current log level based on the latest config.
|
||||
@@ -891,7 +891,7 @@ func (w *Watcher) reloadClients(rescanAuth bool, affectedOAuthProviders []string
|
||||
filtered[id] = auth
|
||||
}
|
||||
w.currentAuths = filtered
|
||||
log.Debugf("applying oauth-model-blacklist to providers %v", affectedOAuthProviders)
|
||||
log.Debugf("applying oauth-excluded-models to providers %v", affectedOAuthProviders)
|
||||
} else {
|
||||
w.currentAuths = nil
|
||||
}
|
||||
@@ -1071,7 +1071,7 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
applyAuthModelBlacklistMeta(a, cfg, entry.ModelBlacklist, "apikey")
|
||||
applyAuthExcludedModelsMeta(a, cfg, entry.ExcludedModels, "apikey")
|
||||
out = append(out, a)
|
||||
}
|
||||
// Claude API keys -> synthesize auths
|
||||
@@ -1105,7 +1105,7 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
applyAuthModelBlacklistMeta(a, cfg, ck.ModelBlacklist, "apikey")
|
||||
applyAuthExcludedModelsMeta(a, cfg, ck.ExcludedModels, "apikey")
|
||||
out = append(out, a)
|
||||
}
|
||||
// Codex API keys -> synthesize auths
|
||||
@@ -1135,7 +1135,7 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
applyAuthModelBlacklistMeta(a, cfg, ck.ModelBlacklist, "apikey")
|
||||
applyAuthExcludedModelsMeta(a, cfg, ck.ExcludedModels, "apikey")
|
||||
out = append(out, a)
|
||||
}
|
||||
for i := range cfg.OpenAICompatibility {
|
||||
@@ -1296,11 +1296,11 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
applyAuthModelBlacklistMeta(a, cfg, nil, "oauth")
|
||||
applyAuthExcludedModelsMeta(a, cfg, nil, "oauth")
|
||||
if provider == "gemini-cli" {
|
||||
if virtuals := synthesizeGeminiVirtualAuths(a, metadata, now); len(virtuals) > 0 {
|
||||
for _, v := range virtuals {
|
||||
applyAuthModelBlacklistMeta(v, cfg, nil, "oauth")
|
||||
applyAuthExcludedModelsMeta(v, cfg, nil, "oauth")
|
||||
}
|
||||
out = append(out, a)
|
||||
out = append(out, virtuals...)
|
||||
@@ -1693,10 +1693,10 @@ func buildConfigChangeDetails(oldCfg, newCfg *config.Config) []string {
|
||||
if !equalStringMap(o.Headers, n.Headers) {
|
||||
changes = append(changes, fmt.Sprintf("gemini[%d].headers: updated", i))
|
||||
}
|
||||
oldBL := summarizeModelBlacklist(o.ModelBlacklist)
|
||||
newBL := summarizeModelBlacklist(n.ModelBlacklist)
|
||||
if oldBL.hash != newBL.hash {
|
||||
changes = append(changes, fmt.Sprintf("gemini[%d].model-blacklist: updated (%d -> %d entries)", i, oldBL.count, newBL.count))
|
||||
oldExcluded := summarizeExcludedModels(o.ExcludedModels)
|
||||
newExcluded := summarizeExcludedModels(n.ExcludedModels)
|
||||
if oldExcluded.hash != newExcluded.hash {
|
||||
changes = append(changes, fmt.Sprintf("gemini[%d].excluded-models: updated (%d -> %d entries)", i, oldExcluded.count, newExcluded.count))
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(trimStrings(oldCfg.GlAPIKey), trimStrings(newCfg.GlAPIKey)) {
|
||||
@@ -1726,10 +1726,10 @@ func buildConfigChangeDetails(oldCfg, newCfg *config.Config) []string {
|
||||
if !equalStringMap(o.Headers, n.Headers) {
|
||||
changes = append(changes, fmt.Sprintf("claude[%d].headers: updated", i))
|
||||
}
|
||||
oldBL := summarizeModelBlacklist(o.ModelBlacklist)
|
||||
newBL := summarizeModelBlacklist(n.ModelBlacklist)
|
||||
if oldBL.hash != newBL.hash {
|
||||
changes = append(changes, fmt.Sprintf("claude[%d].model-blacklist: updated (%d -> %d entries)", i, oldBL.count, newBL.count))
|
||||
oldExcluded := summarizeExcludedModels(o.ExcludedModels)
|
||||
newExcluded := summarizeExcludedModels(n.ExcludedModels)
|
||||
if oldExcluded.hash != newExcluded.hash {
|
||||
changes = append(changes, fmt.Sprintf("claude[%d].excluded-models: updated (%d -> %d entries)", i, oldExcluded.count, newExcluded.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1756,15 +1756,15 @@ func buildConfigChangeDetails(oldCfg, newCfg *config.Config) []string {
|
||||
if !equalStringMap(o.Headers, n.Headers) {
|
||||
changes = append(changes, fmt.Sprintf("codex[%d].headers: updated", i))
|
||||
}
|
||||
oldBL := summarizeModelBlacklist(o.ModelBlacklist)
|
||||
newBL := summarizeModelBlacklist(n.ModelBlacklist)
|
||||
if oldBL.hash != newBL.hash {
|
||||
changes = append(changes, fmt.Sprintf("codex[%d].model-blacklist: updated (%d -> %d entries)", i, oldBL.count, newBL.count))
|
||||
oldExcluded := summarizeExcludedModels(o.ExcludedModels)
|
||||
newExcluded := summarizeExcludedModels(n.ExcludedModels)
|
||||
if oldExcluded.hash != newExcluded.hash {
|
||||
changes = append(changes, fmt.Sprintf("codex[%d].excluded-models: updated (%d -> %d entries)", i, oldExcluded.count, newExcluded.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if entries, _ := diffOAuthBlacklistChanges(oldCfg.OAuthModelBlacklist, newCfg.OAuthModelBlacklist); len(entries) > 0 {
|
||||
if entries, _ := diffOAuthExcludedModelChanges(oldCfg.OAuthExcludedModels, newCfg.OAuthExcludedModels); len(entries) > 0 {
|
||||
changes = append(changes, entries...)
|
||||
}
|
||||
|
||||
|
||||
@@ -665,32 +665,32 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
if compatDetected {
|
||||
provider = "openai-compatibility"
|
||||
}
|
||||
blacklist := s.oauthBlacklist(provider, authKind)
|
||||
excluded := s.oauthExcludedModels(provider, authKind)
|
||||
var models []*ModelInfo
|
||||
switch provider {
|
||||
case "gemini":
|
||||
models = registry.GetGeminiModels()
|
||||
if entry := s.resolveConfigGeminiKey(a); entry != nil {
|
||||
if authKind == "apikey" {
|
||||
blacklist = entry.ModelBlacklist
|
||||
excluded = entry.ExcludedModels
|
||||
}
|
||||
}
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "vertex":
|
||||
// Vertex AI Gemini supports the same model identifiers as Gemini.
|
||||
models = registry.GetGeminiVertexModels()
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "gemini-cli":
|
||||
models = registry.GetGeminiCLIModels()
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "aistudio":
|
||||
models = registry.GetAIStudioModels()
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "antigravity":
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
models = executor.FetchAntigravityModels(ctx, a, s.cfg)
|
||||
cancel()
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "claude":
|
||||
models = registry.GetClaudeModels()
|
||||
if entry := s.resolveConfigClaudeKey(a); entry != nil {
|
||||
@@ -698,24 +698,24 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
models = buildClaudeConfigModels(entry)
|
||||
}
|
||||
if authKind == "apikey" {
|
||||
blacklist = entry.ModelBlacklist
|
||||
excluded = entry.ExcludedModels
|
||||
}
|
||||
}
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "codex":
|
||||
models = registry.GetOpenAIModels()
|
||||
if entry := s.resolveConfigCodexKey(a); entry != nil {
|
||||
if authKind == "apikey" {
|
||||
blacklist = entry.ModelBlacklist
|
||||
excluded = entry.ExcludedModels
|
||||
}
|
||||
}
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "qwen":
|
||||
models = registry.GetQwenModels()
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "iflow":
|
||||
models = registry.GetIFlowModels()
|
||||
models = applyModelBlacklist(models, blacklist)
|
||||
models = applyExcludedModels(models, excluded)
|
||||
default:
|
||||
// Handle OpenAI-compatibility providers by name using config
|
||||
if s.cfg != nil {
|
||||
@@ -900,7 +900,7 @@ func (s *Service) resolveConfigCodexKey(auth *coreauth.Auth) *config.CodexKey {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) oauthBlacklist(provider, authKind string) []string {
|
||||
func (s *Service) oauthExcludedModels(provider, authKind string) []string {
|
||||
cfg := s.cfg
|
||||
if cfg == nil {
|
||||
return nil
|
||||
@@ -910,15 +910,15 @@ func (s *Service) oauthBlacklist(provider, authKind string) []string {
|
||||
if authKindKey == "apikey" {
|
||||
return nil
|
||||
}
|
||||
return cfg.OAuthModelBlacklist[providerKey]
|
||||
return cfg.OAuthExcludedModels[providerKey]
|
||||
}
|
||||
|
||||
func applyModelBlacklist(models []*ModelInfo, blacklist []string) []*ModelInfo {
|
||||
if len(models) == 0 || len(blacklist) == 0 {
|
||||
func applyExcludedModels(models []*ModelInfo, excluded []string) []*ModelInfo {
|
||||
if len(models) == 0 || len(excluded) == 0 {
|
||||
return models
|
||||
}
|
||||
blocked := make(map[string]struct{}, len(blacklist))
|
||||
for _, item := range blacklist {
|
||||
blocked := make(map[string]struct{}, len(excluded))
|
||||
for _, item := range excluded {
|
||||
if trimmed := strings.TrimSpace(item); trimmed != "" {
|
||||
blocked[strings.ToLower(trimmed)] = struct{}{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user