mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
fix(executor): improve model compatibility handling for OpenAI-compatibility
Enhances payload handling by introducing OpenAI-compatibility checks and refining how reasoning metadata is resolved, ensuring broader model support.
This commit is contained in:
@@ -52,10 +52,14 @@ func applyReasoningEffortMetadata(payload []byte, metadata map[string]any, model
|
|||||||
if len(metadata) == 0 {
|
if len(metadata) == 0 {
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
if !util.ModelSupportsThinking(model) {
|
if field == "" {
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
if field == "" {
|
baseModel := util.ResolveOriginalModel(model, metadata)
|
||||||
|
if baseModel == "" {
|
||||||
|
baseModel = model
|
||||||
|
}
|
||||||
|
if !util.ModelSupportsThinking(baseModel) && !util.IsOpenAICompatibilityModel(baseModel) {
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
if effort, ok := util.ReasoningEffortFromMetadata(metadata); ok && effort != "" {
|
if effort, ok := util.ReasoningEffortFromMetadata(metadata); ok && effort != "" {
|
||||||
@@ -226,6 +230,9 @@ func normalizeThinkingConfig(payload []byte, model string) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !util.ModelSupportsThinking(model) {
|
if !util.ModelSupportsThinking(model) {
|
||||||
|
if util.IsOpenAICompatibilityModel(model) {
|
||||||
|
return payload
|
||||||
|
}
|
||||||
return stripThinkingFields(payload)
|
return stripThinkingFields(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,33 +25,33 @@ func ModelSupportsThinking(model string) bool {
|
|||||||
// or min (0 if zero is allowed and mid <= 0).
|
// or min (0 if zero is allowed and mid <= 0).
|
||||||
func NormalizeThinkingBudget(model string, budget int) int {
|
func NormalizeThinkingBudget(model string, budget int) int {
|
||||||
if budget == -1 { // dynamic
|
if budget == -1 { // dynamic
|
||||||
if found, min, max, zeroAllowed, dynamicAllowed := thinkingRangeFromRegistry(model); found {
|
if found, minBudget, maxBudget, zeroAllowed, dynamicAllowed := thinkingRangeFromRegistry(model); found {
|
||||||
if dynamicAllowed {
|
if dynamicAllowed {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
mid := (min + max) / 2
|
mid := (minBudget + maxBudget) / 2
|
||||||
if mid <= 0 && zeroAllowed {
|
if mid <= 0 && zeroAllowed {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if mid <= 0 {
|
if mid <= 0 {
|
||||||
return min
|
return minBudget
|
||||||
}
|
}
|
||||||
return mid
|
return mid
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
if found, min, max, zeroAllowed, _ := thinkingRangeFromRegistry(model); found {
|
if found, minBudget, maxBudget, zeroAllowed, _ := thinkingRangeFromRegistry(model); found {
|
||||||
if budget == 0 {
|
if budget == 0 {
|
||||||
if zeroAllowed {
|
if zeroAllowed {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return min
|
return minBudget
|
||||||
}
|
}
|
||||||
if budget < min {
|
if budget < minBudget {
|
||||||
return min
|
return minBudget
|
||||||
}
|
}
|
||||||
if budget > max {
|
if budget > maxBudget {
|
||||||
return max
|
return maxBudget
|
||||||
}
|
}
|
||||||
return budget
|
return budget
|
||||||
}
|
}
|
||||||
@@ -105,3 +105,16 @@ func NormalizeReasoningEffortLevel(model, effort string) (string, bool) {
|
|||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOpenAICompatibilityModel reports whether the model is registered as an OpenAI-compatibility model.
|
||||||
|
// These models may not advertise Thinking metadata in the registry.
|
||||||
|
func IsOpenAICompatibilityModel(model string) bool {
|
||||||
|
if model == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
info := registry.GetGlobalRegistry().GetModelInfo(model)
|
||||||
|
if info == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.EqualFold(strings.TrimSpace(info.Type), "openai-compatibility")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user