on main help sign in
chore: reasoning for openai providers that support it
1b50cb6Kujtim Hoxha
internal/llm/provider/openai.go+12−1
@@ -2,6 +2,7 @@ package provider
2
2
3import (
3import (
4 "context"
4 "context"
5+ "encoding/json"
5 "errors"
6 "errors"
6 "fmt"
7 "fmt"
7 "io"
8 "io"
@@ -348,8 +349,18 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
348 chunk.Choices[0].Delta.ToolCalls[0].Index = 0
349 chunk.Choices[0].Delta.ToolCalls[0].Index = 0
349 }
350 }
350 acc.AddChunk(chunk)
351 acc.AddChunk(chunk)
351− // This fixes multiple tool calls for some providers
352 for i, choice := range chunk.Choices {
352 for i, choice := range chunk.Choices {
353+ reasoning, ok := choice.Delta.JSON.ExtraFields["reasoning"]
354+ if ok && reasoning.Raw() != "" {
355+ reasoningStr := ""
356+ json.Unmarshal([]byte(reasoning.Raw()), &reasoningStr)
357+ if reasoningStr != "" {
358+ eventChan <- ProviderEvent{
359+ Type: EventThinkingDelta,
360+ Thinking: reasoningStr,
361+ }
362+ }
363+ }
353 if choice.Delta.Content != "" {
364 if choice.Delta.Content != "" {
354 eventChan <- ProviderEvent{
365 eventChan <- ProviderEvent{
355 Type: EventContentDelta,
366 Type: EventContentDelta,
internal/tui/components/chat/messages/messages.go+3
@@ -274,6 +274,9 @@ func (m *messageCmp) renderThinkingContent() string {
274 if reasoningContent.StartedAt > 0 {
274 if reasoningContent.StartedAt > 0 {
275 duration := m.message.ThinkingDuration()
275 duration := m.message.ThinkingDuration()
276 if reasoningContent.FinishedAt > 0 {
276 if reasoningContent.FinishedAt > 0 {
277+ if duration.String() == "0s" {
278+ return ""
279+ }
277 m.anim.SetLabel("")
280 m.anim.SetLabel("")
278 opts := core.StatusOpts{
281 opts := core.StatusOpts{
279 Title: "Thought for",
282 Title: "Thought for",