Files
CLIProxyAPI/internal/modelconfig/model_info.go
Luis Pater ad9e456d4a feat(claude): support between_tools thinking disable type and adaptive fallbacks
- Add `DisableType` support to plugin host adapters and registry mappings.
- Route disabled thinking to `between_tools` for models like Claude Sonnet 5.5.
- Fall back to low-effort adaptive thinking for models that reject disabled states.

Closes: #6698
2026-10-17 13:56:34 +08:00

62 lines
1.8 KiB
Go

package modelconfig
import (
"strings"
"github.com/router-for-me/CLIProxyAPI/v8/internal/registry"
"github.com/router-for-me/CLIProxyAPI/v8/internal/thinking"
)
// ResolveModelInfo returns a private capability snapshot for a configured model.
// Static capabilities come from the suffix-free upstream name, while explicit
// configuration takes precedence.
func ResolveModelInfo(name, modelType string, support *registry.ThinkingSupport) *registry.ModelInfo {
trimmedName := strings.TrimSpace(name)
baseName := strings.TrimSpace(thinking.ParseSuffix(trimmedName).ModelName)
info := registry.LookupStaticModelInfo(baseName)
if info == nil {
info = &registry.ModelInfo{}
}
info.ID = trimmedName
info.Type = strings.TrimSpace(modelType)
if support != nil {
normalized := NormalizeThinkingSupport(support)
// Configured levels replace the catalog entry, but the way a known model
// turns thinking off is an upstream API fact, not a level choice.
if normalized.DisableType == "" && info.Thinking != nil {
normalized.DisableType = info.Thinking.DisableType
}
info.Thinking = normalized
}
info.UserDefined = false
return info
}
// NormalizeThinkingSupport clones and normalizes configured reasoning levels.
func NormalizeThinkingSupport(raw *registry.ThinkingSupport) *registry.ThinkingSupport {
if raw == nil {
return nil
}
normalized := *raw
normalized.Levels = nil
seen := make(map[string]struct{}, len(raw.Levels))
for _, value := range raw.Levels {
level := strings.ToLower(strings.TrimSpace(value))
if level == "" {
continue
}
switch level {
case "none":
normalized.ZeroAllowed = true
case "auto":
normalized.DynamicAllowed = true
}
if _, exists := seen[level]; exists {
continue
}
seen[level] = struct{}{}
normalized.Levels = append(normalized.Levels, level)
}
return &normalized
}