mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
feat(cliproxy): enhance OpenAI compatibility detection and executor registration
- Added `openAICompatInfoFromAuth` helper for streamlined compatibility checks. - Improved OpenAI compatibility provider handling and executor initialization logic. - Adjusted model routing to support OpenAI-compatibility attributes.
This commit is contained in:
@@ -232,10 +232,40 @@ func (s *Service) applyCoreAuthRemoval(ctx context.Context, id string) {
|
||||
}
|
||||
}
|
||||
|
||||
func openAICompatInfoFromAuth(a *coreauth.Auth) (providerKey string, compatName string, ok bool) {
|
||||
if a == nil {
|
||||
return "", "", false
|
||||
}
|
||||
if len(a.Attributes) > 0 {
|
||||
providerKey = strings.TrimSpace(a.Attributes["provider_key"])
|
||||
compatName = strings.TrimSpace(a.Attributes["compat_name"])
|
||||
if providerKey != "" || compatName != "" {
|
||||
if providerKey == "" {
|
||||
providerKey = compatName
|
||||
}
|
||||
return strings.ToLower(providerKey), compatName, true
|
||||
}
|
||||
}
|
||||
if strings.EqualFold(strings.TrimSpace(a.Provider), "openai-compatibility") {
|
||||
return "openai-compatibility", strings.TrimSpace(a.Label), true
|
||||
}
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
func (s *Service) ensureExecutorsForAuth(a *coreauth.Auth) {
|
||||
if s == nil || a == nil {
|
||||
return
|
||||
}
|
||||
if compatProviderKey, _, isCompat := openAICompatInfoFromAuth(a); isCompat {
|
||||
if compatProviderKey == "" {
|
||||
compatProviderKey = strings.ToLower(strings.TrimSpace(a.Provider))
|
||||
}
|
||||
if compatProviderKey == "" {
|
||||
compatProviderKey = "openai-compatibility"
|
||||
}
|
||||
s.coreManager.RegisterExecutor(executor.NewOpenAICompatExecutor(compatProviderKey, s.cfg))
|
||||
return
|
||||
}
|
||||
switch strings.ToLower(a.Provider) {
|
||||
case "gemini":
|
||||
s.coreManager.RegisterExecutor(executor.NewGeminiExecutor(s.cfg))
|
||||
@@ -484,6 +514,10 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
}
|
||||
}
|
||||
provider := strings.ToLower(strings.TrimSpace(a.Provider))
|
||||
compatProviderKey, compatDisplayName, compatDetected := openAICompatInfoFromAuth(a)
|
||||
if compatDetected {
|
||||
provider = "openai-compatibility"
|
||||
}
|
||||
var models []*ModelInfo
|
||||
switch provider {
|
||||
case "gemini":
|
||||
@@ -506,6 +540,15 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
providerKey := provider
|
||||
compatName := strings.TrimSpace(a.Provider)
|
||||
isCompatAuth := false
|
||||
if compatDetected {
|
||||
if compatProviderKey != "" {
|
||||
providerKey = compatProviderKey
|
||||
}
|
||||
if compatDisplayName != "" {
|
||||
compatName = compatDisplayName
|
||||
}
|
||||
isCompatAuth = true
|
||||
}
|
||||
if strings.EqualFold(providerKey, "openai-compatibility") {
|
||||
isCompatAuth = true
|
||||
if a.Attributes != nil {
|
||||
|
||||
Reference in New Issue
Block a user