Switched to streaming

This commit is contained in:
Pavel Pivovarov
2025-12-15 16:00:58 +11:00
parent 1d659006ed
commit 35733aa3e2
2 changed files with 88 additions and 16 deletions

11
main.go
View File

@@ -138,9 +138,13 @@ func processQuery(ctx context.Context, client *llm.Client, messages []openai.Cha
Content: userInput,
})
// Get response from LLM
// Print blank line before streaming starts
fmt.Println()
response, updatedMessages, err := client.Chat(ctx, messages)
// Get response from LLM with streaming
_, updatedMessages, err := client.Chat(ctx, messages, func(chunk string) {
fmt.Print(chunk)
})
if err != nil {
fmt.Fprintf(os.Stderr, "\nError: %v\n\n", err)
// Remove the failed user message
@@ -150,9 +154,8 @@ func processQuery(ctx context.Context, client *llm.Client, messages []openai.Cha
// Update messages with the full conversation history
messages = updatedMessages
// Print response with empty line before it
// Print newline after streaming completes
fmt.Println()
fmt.Println(response)
fmt.Println()
return messages