fix(thinking): use LookupModelInfo for model data

This commit is contained in:
hkfires
2026-01-14 23:02:27 +08:00
parent 6e4a602c60
commit ed8b0f25ee
9 changed files with 9 additions and 9 deletions

View File

@@ -560,7 +560,7 @@ func ensureMaxTokensForThinking(modelName string, body []byte) []byte {
// Look up the model's max completion tokens from the registry // Look up the model's max completion tokens from the registry
maxCompletionTokens := 0 maxCompletionTokens := 0
if modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName); modelInfo != nil { if modelInfo := registry.LookupModelInfo(modelName); modelInfo != nil {
maxCompletionTokens = modelInfo.MaxCompletionTokens maxCompletionTokens = modelInfo.MaxCompletionTokens
} }

View File

@@ -388,7 +388,7 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
// Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled
if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil { if modelInfo != nil && modelInfo.Thinking != nil {
if t.Get("type").String() == "enabled" { if t.Get("type").String() == "enabled" {
if b := t.Get("budget_tokens"); b.Exists() && b.Type == gjson.Number { if b := t.Get("budget_tokens"); b.Exists() && b.Type == gjson.Number {

View File

@@ -118,7 +118,7 @@ func ConvertGeminiRequestToClaude(modelName string, inputRawJSON []byte, stream
// Include thoughts configuration for reasoning process visibility // Include thoughts configuration for reasoning process visibility
// Only apply for models that support thinking and use numeric budgets, not discrete levels. // Only apply for models that support thinking and use numeric budgets, not discrete levels.
if thinkingConfig := genConfig.Get("thinkingConfig"); thinkingConfig.Exists() && thinkingConfig.IsObject() { if thinkingConfig := genConfig.Get("thinkingConfig"); thinkingConfig.Exists() && thinkingConfig.IsObject() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 { if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 {
// Check for thinkingBudget first - if present, enable thinking with budget // Check for thinkingBudget first - if present, enable thinking with budget
if thinkingBudget := thinkingConfig.Get("thinkingBudget"); thinkingBudget.Exists() && thinkingBudget.Int() > 0 { if thinkingBudget := thinkingConfig.Get("thinkingBudget"); thinkingBudget.Exists() && thinkingBudget.Int() > 0 {

View File

@@ -67,7 +67,7 @@ func ConvertOpenAIRequestToClaude(modelName string, inputRawJSON []byte, stream
root := gjson.ParseBytes(rawJSON) root := gjson.ParseBytes(rawJSON)
if v := root.Get("reasoning_effort"); v.Exists() { if v := root.Get("reasoning_effort"); v.Exists() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 { if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 {
effort := strings.ToLower(strings.TrimSpace(v.String())) effort := strings.ToLower(strings.TrimSpace(v.String()))
if effort != "" { if effort != "" {

View File

@@ -55,7 +55,7 @@ func ConvertOpenAIResponsesRequestToClaude(modelName string, inputRawJSON []byte
root := gjson.ParseBytes(rawJSON) root := gjson.ParseBytes(rawJSON)
if v := root.Get("reasoning.effort"); v.Exists() { if v := root.Get("reasoning.effort"); v.Exists() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 { if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 {
effort := strings.ToLower(strings.TrimSpace(v.String())) effort := strings.ToLower(strings.TrimSpace(v.String()))
if effort != "" { if effort != "" {

View File

@@ -221,7 +221,7 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
// Convert thinking.budget_tokens to reasoning.effort for level-based models // Convert thinking.budget_tokens to reasoning.effort for level-based models
reasoningEffort := "medium" // default reasoningEffort := "medium" // default
if thinkingConfig := rootResult.Get("thinking"); thinkingConfig.Exists() && thinkingConfig.IsObject() { if thinkingConfig := rootResult.Get("thinking"); thinkingConfig.Exists() && thinkingConfig.IsObject() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
switch thinkingConfig.Get("type").String() { switch thinkingConfig.Get("type").String() {
case "enabled": case "enabled":
if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) > 0 { if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) > 0 {

View File

@@ -253,7 +253,7 @@ func ConvertGeminiRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
reasoningEffort := "medium" // default reasoningEffort := "medium" // default
if genConfig := root.Get("generationConfig"); genConfig.Exists() { if genConfig := root.Get("generationConfig"); genConfig.Exists() {
if thinkingConfig := genConfig.Get("thinkingConfig"); thinkingConfig.Exists() && thinkingConfig.IsObject() { if thinkingConfig := genConfig.Get("thinkingConfig"); thinkingConfig.Exists() && thinkingConfig.IsObject() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) > 0 { if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) > 0 {
if thinkingBudget := thinkingConfig.Get("thinkingBudget"); thinkingBudget.Exists() { if thinkingBudget := thinkingConfig.Get("thinkingBudget"); thinkingBudget.Exists() {
budget := int(thinkingBudget.Int()) budget := int(thinkingBudget.Int())

View File

@@ -161,7 +161,7 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) []
// Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when type==enabled
if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil { if modelInfo != nil && modelInfo.Thinking != nil {
if t.Get("type").String() == "enabled" { if t.Get("type").String() == "enabled" {
if b := t.Get("budget_tokens"); b.Exists() && b.Type == gjson.Number { if b := t.Get("budget_tokens"); b.Exists() && b.Type == gjson.Number {

View File

@@ -155,7 +155,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
// Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when enabled // Map Anthropic thinking -> Gemini thinkingBudget/include_thoughts when enabled
// Only apply for models that use numeric budgets, not discrete levels. // Only apply for models that use numeric budgets, not discrete levels.
if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() { if t := gjson.GetBytes(rawJSON, "thinking"); t.Exists() && t.IsObject() {
modelInfo := registry.GetGlobalRegistry().GetModelInfo(modelName) modelInfo := registry.LookupModelInfo(modelName)
if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 { if modelInfo != nil && modelInfo.Thinking != nil && len(modelInfo.Thinking.Levels) == 0 {
if t.Get("type").String() == "enabled" { if t.Get("type").String() == "enabled" {
if b := t.Get("budget_tokens"); b.Exists() && b.Type == gjson.Number { if b := t.Get("budget_tokens"); b.Exists() && b.Type == gjson.Number {