Switched to streaming
This commit is contained in:
11
main.go
11
main.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user