fix(model): support the configuration to disable reasoning (#494)

This commit is contained in:
junwen-lee
2025-08-02 20:46:44 +08:00
committed by GitHub
parent ccdb79eb36
commit d11aa71c0a
13 changed files with 58 additions and 17 deletions

View File

@@ -28,6 +28,7 @@ import (
"github.com/cloudwego/eino-ext/components/model/openai"
"github.com/cloudwego/eino-ext/components/model/qwen"
"github.com/ollama/ollama/api"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
"google.golang.org/genai"
"github.com/coze-dev/coze-studio/backend/infra/contract/chatmodel"
@@ -126,6 +127,14 @@ func claudeBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.Too
cfg.SessionToken = config.Claude.SessionToken
cfg.Region = config.Claude.Region
}
if config.EnableThinking != nil {
cfg.Thinking = &claude.Thinking{
Enable: ptr.From(config.EnableThinking),
}
if config.Claude != nil && config.Claude.BudgetTokens != nil {
cfg.Thinking.BudgetTokens = ptr.From(config.Claude.BudgetTokens)
}
}
return claude.NewChatModel(ctx, cfg)
}
@@ -180,6 +189,21 @@ func arkBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.ToolCa
cfg.RetryTimes = config.Ark.RetryTimes
cfg.CustomHeader = config.Ark.CustomHeader
}
if config.EnableThinking != nil {
cfg.Thinking = func() *model.Thinking {
var arkThinkingType model.ThinkingType
switch {
case ptr.From(config.EnableThinking):
arkThinkingType = model.ThinkingTypeEnabled
default:
arkThinkingType = model.ThinkingTypeDisabled
}
return &model.Thinking{
Type: arkThinkingType,
}
}()
}
return ark.NewChatModel(ctx, cfg)
}
@@ -200,6 +224,9 @@ func ollamaBuilder(ctx context.Context, config *chatmodel.Config) (chatmodel.Too
Stop: config.Stop,
},
}
if config.EnableThinking != nil {
cfg.Thinking = config.EnableThinking
}
return ollama.NewChatModel(ctx, cfg)
}