feat: merge per-account excluded_models with global config

This commit is contained in:
RGBadmin
2026-02-11 15:21:15 +08:00
parent 5ed2133ff9
commit b93026d83a

View File

@@ -53,6 +53,8 @@ func (g *StableIDGenerator) Next(kind string, parts ...string) (string, string)
// ApplyAuthExcludedModelsMeta applies excluded models metadata to an auth entry. // ApplyAuthExcludedModelsMeta applies excluded models metadata to an auth entry.
// It computes a hash of excluded models and sets the auth_kind attribute. // It computes a hash of excluded models and sets the auth_kind attribute.
// For OAuth entries, perKey (from the JSON file's excluded-models field) is merged
// with the global oauth-excluded-models config for the provider.
func ApplyAuthExcludedModelsMeta(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 { if auth == nil || cfg == nil {
return return
@@ -72,9 +74,13 @@ func ApplyAuthExcludedModelsMeta(auth *coreauth.Auth, cfg *config.Config, perKey
} }
if authKindKey == "apikey" { if authKindKey == "apikey" {
add(perKey) add(perKey)
} else if cfg.OAuthExcludedModels != nil { } else {
providerKey := strings.ToLower(strings.TrimSpace(auth.Provider)) // For OAuth: merge per-account excluded models with global provider-level exclusions
add(cfg.OAuthExcludedModels[providerKey]) add(perKey)
if cfg.OAuthExcludedModels != nil {
providerKey := strings.ToLower(strings.TrimSpace(auth.Provider))
add(cfg.OAuthExcludedModels[providerKey])
}
} }
combined := make([]string, 0, len(seen)) combined := make([]string, 0, len(seen))
for k := range seen { for k := range seen {
@@ -88,6 +94,10 @@ func ApplyAuthExcludedModelsMeta(auth *coreauth.Auth, cfg *config.Config, perKey
if hash != "" { if hash != "" {
auth.Attributes["excluded_models_hash"] = hash auth.Attributes["excluded_models_hash"] = hash
} }
// Store the combined excluded models list so that routing can read it at runtime
if len(combined) > 0 {
auth.Attributes["excluded_models"] = strings.Join(combined, ",")
}
if authKind != "" { if authKind != "" {
auth.Attributes["auth_kind"] = authKind auth.Attributes["auth_kind"] = authKind
} }