feat(config): add support for disabling OpenAI compatibility providers
- Introduced a `Disabled` flag to OpenAI compatibility configurations. - Updated routing, auth selection, and API handling logic to respect the `Disabled` state. - Extended relevant APIs, YAML configurations, and data structures to include the `Disabled` field. - Adjusted all relevant loops and filters to skip disabled providers. Closes: #3060 #3059 #2977
This commit is contained in:
@@ -229,6 +229,7 @@ nonstream-keepalive-interval: 0
|
|||||||
# OpenAI compatibility providers
|
# OpenAI compatibility providers
|
||||||
# openai-compatibility:
|
# openai-compatibility:
|
||||||
# - name: "openrouter" # The name of the provider; it will be used in the user agent and other places.
|
# - name: "openrouter" # The name of the provider; it will be used in the user agent and other places.
|
||||||
|
# disabled: false # optional: set to true to disable this provider without removing it
|
||||||
# prefix: "test" # optional: require calls like "test/kimi-k2" to target this provider's credentials
|
# prefix: "test" # optional: require calls like "test/kimi-k2" to target this provider's credentials
|
||||||
# base-url: "https://openrouter.ai/api/v1" # The base URL of the provider.
|
# base-url: "https://openrouter.ai/api/v1" # The base URL of the provider.
|
||||||
# headers:
|
# headers:
|
||||||
|
|||||||
@@ -766,6 +766,9 @@ func resolveOpenAICompatAPIKeyProxyURL(cfg *config.Config, auth *coreauth.Auth,
|
|||||||
|
|
||||||
for i := range cfg.OpenAICompatibility {
|
for i := range cfg.OpenAICompatibility {
|
||||||
compat := &cfg.OpenAICompatibility[i]
|
compat := &cfg.OpenAICompatibility[i]
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
if candidate != "" && strings.EqualFold(strings.TrimSpace(candidate), compat.Name) {
|
if candidate != "" && strings.EqualFold(strings.TrimSpace(candidate), compat.Name) {
|
||||||
for j := range compat.APIKeyEntries {
|
for j := range compat.APIKeyEntries {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type openAICompatibilityAPIKeyWithAuthIndex struct {
|
|||||||
type openAICompatibilityWithAuthIndex struct {
|
type openAICompatibilityWithAuthIndex struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Priority int `json:"priority,omitempty"`
|
Priority int `json:"priority,omitempty"`
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
Prefix string `json:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty"`
|
||||||
BaseURL string `json:"base-url"`
|
BaseURL string `json:"base-url"`
|
||||||
APIKeyEntries []openAICompatibilityAPIKeyWithAuthIndex `json:"api-key-entries,omitempty"`
|
APIKeyEntries []openAICompatibilityAPIKeyWithAuthIndex `json:"api-key-entries,omitempty"`
|
||||||
@@ -215,6 +216,7 @@ func (h *Handler) openAICompatibilityWithAuthIndex() []openAICompatibilityWithAu
|
|||||||
response := openAICompatibilityWithAuthIndex{
|
response := openAICompatibilityWithAuthIndex{
|
||||||
Name: entry.Name,
|
Name: entry.Name,
|
||||||
Priority: entry.Priority,
|
Priority: entry.Priority,
|
||||||
|
Disabled: entry.Disabled,
|
||||||
Prefix: entry.Prefix,
|
Prefix: entry.Prefix,
|
||||||
BaseURL: entry.BaseURL,
|
BaseURL: entry.BaseURL,
|
||||||
Models: entry.Models,
|
Models: entry.Models,
|
||||||
|
|||||||
@@ -464,6 +464,7 @@ func (h *Handler) PatchOpenAICompat(c *gin.Context) {
|
|||||||
type openAICompatPatch struct {
|
type openAICompatPatch struct {
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Prefix *string `json:"prefix"`
|
Prefix *string `json:"prefix"`
|
||||||
|
Disabled *bool `json:"disabled"`
|
||||||
BaseURL *string `json:"base-url"`
|
BaseURL *string `json:"base-url"`
|
||||||
APIKeyEntries *[]config.OpenAICompatibilityAPIKey `json:"api-key-entries"`
|
APIKeyEntries *[]config.OpenAICompatibilityAPIKey `json:"api-key-entries"`
|
||||||
Models *[]config.OpenAICompatibilityModel `json:"models"`
|
Models *[]config.OpenAICompatibilityModel `json:"models"`
|
||||||
@@ -506,6 +507,9 @@ func (h *Handler) PatchOpenAICompat(c *gin.Context) {
|
|||||||
if body.Value.Prefix != nil {
|
if body.Value.Prefix != nil {
|
||||||
entry.Prefix = strings.TrimSpace(*body.Value.Prefix)
|
entry.Prefix = strings.TrimSpace(*body.Value.Prefix)
|
||||||
}
|
}
|
||||||
|
if body.Value.Disabled != nil {
|
||||||
|
entry.Disabled = *body.Value.Disabled
|
||||||
|
}
|
||||||
if body.Value.BaseURL != nil {
|
if body.Value.BaseURL != nil {
|
||||||
trimmed := strings.TrimSpace(*body.Value.BaseURL)
|
trimmed := strings.TrimSpace(*body.Value.BaseURL)
|
||||||
if trimmed == "" {
|
if trimmed == "" {
|
||||||
|
|||||||
@@ -1100,6 +1100,9 @@ func (s *Server) UpdateClients(cfg *config.Config) {
|
|||||||
openAICompatCount := 0
|
openAICompatCount := 0
|
||||||
for i := range cfg.OpenAICompatibility {
|
for i := range cfg.OpenAICompatibility {
|
||||||
entry := cfg.OpenAICompatibility[i]
|
entry := cfg.OpenAICompatibility[i]
|
||||||
|
if entry.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
openAICompatCount += len(entry.APIKeyEntries)
|
openAICompatCount += len(entry.APIKeyEntries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -519,6 +519,9 @@ type OpenAICompatibility struct {
|
|||||||
// Higher values are preferred; defaults to 0.
|
// Higher values are preferred; defaults to 0.
|
||||||
Priority int `yaml:"priority,omitempty" json:"priority,omitempty"`
|
Priority int `yaml:"priority,omitempty" json:"priority,omitempty"`
|
||||||
|
|
||||||
|
// Disabled prevents this provider from being used for routing.
|
||||||
|
Disabled bool `yaml:"disabled,omitempty" json:"disabled,omitempty"`
|
||||||
|
|
||||||
// Prefix optionally namespaces model aliases for this provider (e.g., "teamA/kimi-k2").
|
// Prefix optionally namespaces model aliases for this provider (e.g., "teamA/kimi-k2").
|
||||||
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"`
|
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"`
|
||||||
|
|
||||||
|
|||||||
@@ -378,6 +378,9 @@ func (e *OpenAICompatExecutor) resolveCompatConfig(auth *cliproxyauth.Auth) *con
|
|||||||
}
|
}
|
||||||
for i := range e.cfg.OpenAICompatibility {
|
for i := range e.cfg.OpenAICompatibility {
|
||||||
compat := &e.cfg.OpenAICompatibility[i]
|
compat := &e.cfg.OpenAICompatibility[i]
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
if candidate != "" && strings.EqualFold(strings.TrimSpace(candidate), compat.Name) {
|
if candidate != "" && strings.EqualFold(strings.TrimSpace(candidate), compat.Name) {
|
||||||
return compat
|
return compat
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ func IsOpenAICompatibilityAlias(modelName string, cfg *config.Config) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, compat := range cfg.OpenAICompatibility {
|
for _, compat := range cfg.OpenAICompatibility {
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, model := range compat.Models {
|
for _, model := range compat.Models {
|
||||||
if model.Alias == modelName {
|
if model.Alias == modelName {
|
||||||
return true
|
return true
|
||||||
@@ -123,6 +126,9 @@ func GetOpenAICompatibilityConfig(alias string, cfg *config.Config) (*config.Ope
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, compat := range cfg.OpenAICompatibility {
|
for _, compat := range cfg.OpenAICompatibility {
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, model := range compat.Models {
|
for _, model := range compat.Models {
|
||||||
if model.Alias == alias {
|
if model.Alias == alias {
|
||||||
return &compat, &model
|
return &compat, &model
|
||||||
|
|||||||
@@ -357,6 +357,9 @@ func BuildAPIKeyClients(cfg *config.Config) (int, int, int, int, int) {
|
|||||||
}
|
}
|
||||||
if len(cfg.OpenAICompatibility) > 0 {
|
if len(cfg.OpenAICompatibility) > 0 {
|
||||||
for _, compatConfig := range cfg.OpenAICompatibility {
|
for _, compatConfig := range cfg.OpenAICompatibility {
|
||||||
|
if compatConfig.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
openAICompatCount += len(compatConfig.APIKeyEntries)
|
openAICompatCount += len(compatConfig.APIKeyEntries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ func describeOpenAICompatibilityUpdate(oldEntry, newEntry config.OpenAICompatibi
|
|||||||
oldModelCount := countOpenAIModels(oldEntry.Models)
|
oldModelCount := countOpenAIModels(oldEntry.Models)
|
||||||
newModelCount := countOpenAIModels(newEntry.Models)
|
newModelCount := countOpenAIModels(newEntry.Models)
|
||||||
details := make([]string, 0, 3)
|
details := make([]string, 0, 3)
|
||||||
|
if oldEntry.Disabled != newEntry.Disabled {
|
||||||
|
details = append(details, fmt.Sprintf("disabled %t -> %t", oldEntry.Disabled, newEntry.Disabled))
|
||||||
|
}
|
||||||
if oldKeyCount != newKeyCount {
|
if oldKeyCount != newKeyCount {
|
||||||
details = append(details, fmt.Sprintf("api-keys %d -> %d", oldKeyCount, newKeyCount))
|
details = append(details, fmt.Sprintf("api-keys %d -> %d", oldKeyCount, newKeyCount))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,6 +194,9 @@ func (s *ConfigSynthesizer) synthesizeOpenAICompat(ctx *SynthesisContext) []*cor
|
|||||||
out := make([]*coreauth.Auth, 0)
|
out := make([]*coreauth.Auth, 0)
|
||||||
for i := range cfg.OpenAICompatibility {
|
for i := range cfg.OpenAICompatibility {
|
||||||
compat := &cfg.OpenAICompatibility[i]
|
compat := &cfg.OpenAICompatibility[i]
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
prefix := strings.TrimSpace(compat.Prefix)
|
prefix := strings.TrimSpace(compat.Prefix)
|
||||||
providerName := strings.ToLower(strings.TrimSpace(compat.Name))
|
providerName := strings.ToLower(strings.TrimSpace(compat.Name))
|
||||||
if providerName == "" {
|
if providerName == "" {
|
||||||
|
|||||||
@@ -1799,6 +1799,9 @@ func resolveOpenAICompatConfig(cfg *internalconfig.Config, providerKey, compatNa
|
|||||||
}
|
}
|
||||||
for i := range cfg.OpenAICompatibility {
|
for i := range cfg.OpenAICompatibility {
|
||||||
compat := &cfg.OpenAICompatibility[i]
|
compat := &cfg.OpenAICompatibility[i]
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
if candidate != "" && strings.EqualFold(strings.TrimSpace(candidate), compat.Name) {
|
if candidate != "" && strings.EqualFold(strings.TrimSpace(candidate), compat.Name) {
|
||||||
return compat
|
return compat
|
||||||
|
|||||||
@@ -969,6 +969,9 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
|||||||
}
|
}
|
||||||
for i := range s.cfg.OpenAICompatibility {
|
for i := range s.cfg.OpenAICompatibility {
|
||||||
compat := &s.cfg.OpenAICompatibility[i]
|
compat := &s.cfg.OpenAICompatibility[i]
|
||||||
|
if compat.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if strings.EqualFold(compat.Name, compatName) {
|
if strings.EqualFold(compat.Name, compatName) {
|
||||||
isCompatAuth = true
|
isCompatAuth = true
|
||||||
// Convert compatibility models to registry models
|
// Convert compatibility models to registry models
|
||||||
|
|||||||
Reference in New Issue
Block a user