fix(thinking): improve model lookup and validation

This commit is contained in:
hkfires
2026-01-14 16:30:28 +08:00
parent 40ee065eff
commit 7f1b2b3f6e
13 changed files with 78 additions and 137 deletions

View File

@@ -68,9 +68,11 @@ func IsUserDefinedModel(modelInfo *registry.ModelInfo) bool {
//
// Passthrough behavior (returns original body without error):
// - Unknown provider (not in providerAppliers map)
// - modelInfo is nil (model not found in registry)
// - modelInfo.Thinking is nil (model doesn't support thinking)
//
// Note: Unknown models (modelInfo is nil) are treated as user-defined models: we skip
// validation and still apply the thinking config so the upstream can validate it.
//
// Example:
//
// // With suffix - suffix config takes priority
@@ -87,15 +89,13 @@ func ApplyThinking(body []byte, model string, provider string) ([]byte, error) {
}
// 2. Parse suffix and get modelInfo
// First try dynamic registry, then fall back to static lookup
suffixResult := ParseSuffix(model)
baseModel := suffixResult.ModelName
modelInfo := registry.GetGlobalRegistry().GetModelInfo(baseModel)
if modelInfo == nil {
modelInfo = registry.LookupStaticModelInfo(baseModel)
}
modelInfo := registry.LookupModelInfo(baseModel)
// 3. Model capability check
// Unknown models are treated as user-defined so thinking config can still be applied.
// The upstream service is responsible for validating the configuration.
if IsUserDefinedModel(modelInfo) {
return applyUserDefinedModel(body, modelInfo, provider, suffixResult)
}