@@ -19,6 +19,7 @@ import (
1919 "github.com/docker/model-runner/pkg/inference"
2020 dmrm "github.com/docker/model-runner/pkg/inference/models"
2121 "github.com/docker/model-runner/pkg/inference/scheduling"
22+ "github.com/fatih/color"
2223 "github.com/pkg/errors"
2324 "go.opentelemetry.io/otel"
2425)
@@ -413,8 +414,15 @@ func (c *Client) ChatStreaming(backend, model, prompt, apiKey string, outputFunc
413414 return fmt .Errorf ("error response: status=%d body=%s" , resp .StatusCode , body )
414415 }
415416
416- reasoningShown := false
417+ type chatPrinterState int
418+ const (
419+ chatPrinterNone chatPrinterState = iota
420+ chatPrinterReasoning
421+ chatPrinterContent
422+ )
417423
424+ printerState := chatPrinterNone
425+ reasoningFmt := color .New (color .FgWhite ).Add (color .Italic )
418426 scanner := bufio .NewScanner (resp .Body )
419427 for scanner .Scan () {
420428 line := scanner .Text ()
@@ -438,24 +446,24 @@ func (c *Client) ChatStreaming(backend, model, prompt, apiKey string, outputFunc
438446 }
439447
440448 if len (streamResp .Choices ) > 0 {
441- // Handle reasoning content
442449 if streamResp .Choices [0 ].Delta .ReasoningContent != "" {
443- if ! reasoningShown {
444- outputFunc ("\n ## 🤔 Thinking\n \n " )
445- reasoningShown = true
450+ chunk := streamResp .Choices [0 ].Delta .ReasoningContent
451+ if printerState == chatPrinterContent {
452+ outputFunc ("\n \n " )
453+ }
454+ if printerState != chatPrinterReasoning {
455+ reasoningFmt .Println ("Thinking:" )
446456 }
447- // For now, just output reasoning content as plain text
448- outputFunc ( streamResp . Choices [ 0 ]. Delta . ReasoningContent )
457+ printerState = chatPrinterReasoning
458+ reasoningFmt . Print ( chunk )
449459 }
450-
451- // Handle main content
452460 if streamResp .Choices [0 ].Delta .Content != "" {
453- if reasoningShown {
454- outputFunc ( " \n \n --- \n \n " )
455- reasoningShown = false // Prevent showing separator again
461+ chunk := streamResp . Choices [ 0 ]. Delta . Content
462+ if printerState == chatPrinterReasoning {
463+ outputFunc ( " \n \n -- \n \n " )
456464 }
457- // For now, just output content as plain text (streaming without markdown)
458- outputFunc (streamResp . Choices [ 0 ]. Delta . Content )
465+ printerState = chatPrinterContent
466+ outputFunc (chunk )
459467 }
460468 }
461469 }
0 commit comments