diff --git a/pkg/cli/cmd.go b/pkg/cli/cmd.go index efde7af..6aff35f 100644 --- a/pkg/cli/cmd.go +++ b/pkg/cli/cmd.go @@ -112,7 +112,6 @@ var newCmd = &cobra.Command{ ConversationID: conversation.ID, Role: "assistant", } - reply.RenderTTY(false) receiver := make(chan string) @@ -120,6 +119,7 @@ var newCmd = &cobra.Command{ go func() { response <- HandleDelayedResponse(receiver) }() + err = CreateChatCompletionStream(messages, receiver) if err != nil { Fatal("%v\n", err) diff --git a/pkg/cli/openai.go b/pkg/cli/openai.go index 1251426..21d77af 100644 --- a/pkg/cli/openai.go +++ b/pkg/cli/openai.go @@ -25,8 +25,8 @@ func CreateChatCompletionRequest(messages []Message) *openai.ChatCompletionReque } } -// CreateChatCompletion accepts a slice of Message and returns the response -// of the Large Language Model. +// CreateChatCompletion submits a Chat Completion API request and returns the +// response. func CreateChatCompletion(messages []Message) (string, error) { client := openai.NewClient(config.OpenAI.APIKey) resp, err := client.CreateChatCompletion( @@ -41,8 +41,8 @@ func CreateChatCompletion(messages []Message) (string, error) { return resp.Choices[0].Message.Content, nil } -// CreateChatCompletionStream submits an streaming Chat Completion API request -// and sends the received data to the output channel. +// CreateChatCompletionStream submits a streaming Chat Completion API request +// and streams the received response to the provided output channel. func CreateChatCompletionStream(messages []Message, output chan string) error { client := openai.NewClient(config.OpenAI.APIKey) ctx := context.Background() diff --git a/pkg/cli/tty.go b/pkg/cli/tty.go index e2dab81..159da00 100644 --- a/pkg/cli/tty.go +++ b/pkg/cli/tty.go @@ -45,7 +45,9 @@ func HandleDelayedResponse(response chan string) string { firstChunk := true for chunk := range response { if firstChunk { + // notify wait animation that we've received data waitSignal <- "" + // wait for signal that wait animation has completed <-waitSignal firstChunk = false }