mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 04:10:51 +08:00
feat(registry): add client model support check for executor filtering
- Introduced `ClientSupportsModel` function to `ModelRegistry` for verifying client support for specific models. - Integrated model support validation into executor candidate filtering logic. - Updated CLIProxy registry interface to include the new support check method.
This commit is contained in:
@@ -523,6 +523,31 @@ func (r *ModelRegistry) ResumeClientModel(clientID, modelID string) {
|
|||||||
log.Debugf("Resumed client %s for model %s", clientID, modelID)
|
log.Debugf("Resumed client %s for model %s", clientID, modelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientSupportsModel reports whether the client registered support for modelID.
|
||||||
|
func (r *ModelRegistry) ClientSupportsModel(clientID, modelID string) bool {
|
||||||
|
clientID = strings.TrimSpace(clientID)
|
||||||
|
modelID = strings.TrimSpace(modelID)
|
||||||
|
if clientID == "" || modelID == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
|
||||||
|
models, exists := r.clientModels[clientID]
|
||||||
|
if !exists || len(models) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range models {
|
||||||
|
if strings.EqualFold(strings.TrimSpace(id), modelID) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// GetAvailableModels returns all models that have at least one available client
|
// GetAvailableModels returns all models that have at least one available client
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// - handlerType: The handler type to filter models for (e.g., "openai", "claude", "gemini")
|
// - handlerType: The handler type to filter models for (e.g., "openai", "claude", "gemini")
|
||||||
|
|||||||
@@ -841,6 +841,8 @@ func (m *Manager) pickNext(ctx context.Context, provider, model string, opts cli
|
|||||||
return nil, nil, &Error{Code: "executor_not_found", Message: "executor not registered"}
|
return nil, nil, &Error{Code: "executor_not_found", Message: "executor not registered"}
|
||||||
}
|
}
|
||||||
candidates := make([]*Auth, 0, len(m.auths))
|
candidates := make([]*Auth, 0, len(m.auths))
|
||||||
|
modelKey := strings.TrimSpace(model)
|
||||||
|
registryRef := registry.GetGlobalRegistry()
|
||||||
for _, candidate := range m.auths {
|
for _, candidate := range m.auths {
|
||||||
if candidate.Provider != provider || candidate.Disabled {
|
if candidate.Provider != provider || candidate.Disabled {
|
||||||
continue
|
continue
|
||||||
@@ -848,6 +850,9 @@ func (m *Manager) pickNext(ctx context.Context, provider, model string, opts cli
|
|||||||
if _, used := tried[candidate.ID]; used {
|
if _, used := tried[candidate.ID]; used {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if modelKey != "" && registryRef != nil && !registryRef.ClientSupportsModel(candidate.ID, modelKey) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
candidates = append(candidates, candidate)
|
candidates = append(candidates, candidate)
|
||||||
}
|
}
|
||||||
if len(candidates) == 0 {
|
if len(candidates) == 0 {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type ModelRegistry interface {
|
|||||||
UnregisterClient(clientID string)
|
UnregisterClient(clientID string)
|
||||||
SetModelQuotaExceeded(clientID, modelID string)
|
SetModelQuotaExceeded(clientID, modelID string)
|
||||||
ClearModelQuotaExceeded(clientID, modelID string)
|
ClearModelQuotaExceeded(clientID, modelID string)
|
||||||
|
ClientSupportsModel(clientID, modelID string) bool
|
||||||
GetAvailableModels(handlerType string) []map[string]any
|
GetAvailableModels(handlerType string) []map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user