mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
fix(cliproxy): Clear stale compatibility model registrations
Previously, if an OpenAI compatibility configuration was removed from the config file or its model list was emptied, the associated models for that auth entry were not unregistered from the global model registry. This resulted in stale registrations persisting. This change ensures that when an auth entry is identified as being for a compatibility provider, its models are explicitly unregistered if: - The corresponding configuration is found but has an empty model list. - The corresponding configuration is no longer found in the config file.
This commit is contained in:
@@ -508,22 +508,35 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
if s.cfg != nil {
|
||||
providerKey := provider
|
||||
compatName := strings.TrimSpace(a.Provider)
|
||||
isCompatAuth := false
|
||||
if strings.EqualFold(providerKey, "openai-compatibility") {
|
||||
isCompatAuth = true
|
||||
if a.Attributes != nil {
|
||||
if v := strings.TrimSpace(a.Attributes["compat_name"]); v != "" {
|
||||
compatName = v
|
||||
}
|
||||
if v := strings.TrimSpace(a.Attributes["provider_key"]); v != "" {
|
||||
providerKey = strings.ToLower(v)
|
||||
isCompatAuth = true
|
||||
}
|
||||
}
|
||||
if providerKey == "openai-compatibility" && compatName != "" {
|
||||
providerKey = strings.ToLower(compatName)
|
||||
}
|
||||
} else if a.Attributes != nil {
|
||||
if v := strings.TrimSpace(a.Attributes["compat_name"]); v != "" {
|
||||
compatName = v
|
||||
isCompatAuth = true
|
||||
}
|
||||
if v := strings.TrimSpace(a.Attributes["provider_key"]); v != "" {
|
||||
providerKey = strings.ToLower(v)
|
||||
isCompatAuth = true
|
||||
}
|
||||
}
|
||||
for i := range s.cfg.OpenAICompatibility {
|
||||
compat := &s.cfg.OpenAICompatibility[i]
|
||||
if strings.EqualFold(compat.Name, compatName) {
|
||||
isCompatAuth = true
|
||||
// Convert compatibility models to registry models
|
||||
ms := make([]*ModelInfo, 0, len(compat.Models))
|
||||
for j := range compat.Models {
|
||||
@@ -543,10 +556,18 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
providerKey = "openai-compatibility"
|
||||
}
|
||||
GlobalModelRegistry().RegisterClient(a.ID, providerKey, ms)
|
||||
} else {
|
||||
// Ensure stale registrations are cleared when model list becomes empty.
|
||||
GlobalModelRegistry().UnregisterClient(a.ID)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
if isCompatAuth {
|
||||
// No matching provider found or models removed entirely; drop any prior registration.
|
||||
GlobalModelRegistry().UnregisterClient(a.ID)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(models) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user