Formatting/comments
This commit is contained in:
parent
9c9b8fa412
commit
0c2149663f
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user