diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go index e8c980aeb3cc35a51071227093fac8e8cd3a4b0c..1e8364b08cb76ec7210d9937302cd1c647857b2d 100644 --- a/internal/llm/provider/anthropic.go +++ b/internal/llm/provider/anthropic.go @@ -163,6 +163,15 @@ func (a *anthropicClient) finishReason(reason string) message.FinishReason { } } +func (a *anthropicClient) isThinkingEnabled() bool { + cfg := config.Get() + modelConfig := cfg.Models[config.SelectedModelTypeLarge] + if a.providerOptions.modelType == config.SelectedModelTypeSmall { + modelConfig = cfg.Models[config.SelectedModelTypeSmall] + } + return a.Model().CanReason && modelConfig.Think +} + func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, tools []anthropic.ToolUnionParam) anthropic.MessageNewParams { model := a.providerOptions.model(a.providerOptions.modelType) var thinkingParam anthropic.ThinkingConfigParamUnion @@ -177,7 +186,7 @@ func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, to if modelConfig.MaxTokens > 0 { maxTokens = modelConfig.MaxTokens } - if a.Model().CanReason && modelConfig.Think { + if a.isThinkingEnabled() { thinkingParam = anthropic.ThinkingConfigParamOfEnabled(int64(float64(maxTokens) * 0.8)) temperature = anthropic.Float(1) } @@ -222,9 +231,14 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message, slog.Debug("Prepared messages", "messages", string(jsonData)) } + var opts []option.RequestOption + if a.isThinkingEnabled() { + opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14")) + } anthropicResponse, err := a.client.Messages.New( ctx, preparedMessages, + opts..., ) // If there is an error we are going to see if we can retry the call if err != nil { @@ -274,10 +288,15 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message slog.Debug("Prepared messages", "messages", string(jsonData)) } + var opts []option.RequestOption + if a.isThinkingEnabled() { + opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14")) + } + anthropicStream := a.client.Messages.NewStreaming( ctx, preparedMessages, - option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"), + opts..., ) accumulatedMessage := anthropic.Message{} diff --git a/internal/tui/components/chat/messages/messages.go b/internal/tui/components/chat/messages/messages.go index e4def66708c3647e5aafd4562a8dc66323dd05c2..2ffa1601f84fcb9028faf67bd94d70920a193864 100644 --- a/internal/tui/components/chat/messages/messages.go +++ b/internal/tui/components/chat/messages/messages.go @@ -266,7 +266,7 @@ func (m *messageCmp) renderThinkingContent() string { Description: duration.String(), NoIcon: true, } - footer = t.S().Base.PaddingLeft(1).Render(core.Status(opts, m.textWidth()-1)) + return t.S().Base.PaddingLeft(1).Render(core.Status(opts, m.textWidth()-1)) } else if finishReason != nil && finishReason.Reason == message.FinishReasonCanceled { footer = t.S().Base.PaddingLeft(1).Render(m.toMarkdown("*Canceled*")) } else {