Skip to content

Commit dd6296f

Browse files
add simple spinner to chat completion requests
1 parent 895319d commit dd6296f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/pkg/assistants/assistant_chat_completions.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"net/http"
88
"os"
99
"strings"
10+
"time"
1011

12+
"github.com/briandowns/spinner"
1113
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/state"
1214
"github.com/pinecone-io/cli/internal/pkg/utils/log"
1315
"github.com/pinecone-io/cli/internal/pkg/utils/models"
@@ -44,13 +46,17 @@ func GetAssistantChatCompletions(asstName string, msg string, stream bool) (*mod
4446
return nil, err
4547
}
4648

49+
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond)
50+
s.Start()
51+
4752
var resp *models.ChatCompletionModel
4853
if !stream {
4954
resp, err = network.PostAndDecode[models.ChatCompletionRequest, models.ChatCompletionModel](
5055
assistantDataUrl,
5156
fmt.Sprintf(URL_ASSISTANT_CHAT_COMPLETIONS, asstName),
5257
body,
5358
)
59+
s.Stop()
5460
if err != nil {
5561
return nil, err
5662
}
@@ -59,6 +65,7 @@ func GetAssistantChatCompletions(asstName string, msg string, stream bool) (*mod
5965
assistantDataUrl,
6066
fmt.Sprintf(URL_ASSISTANT_CHAT_COMPLETIONS, asstName),
6167
body,
68+
s,
6269
)
6370
if err != nil {
6471
return nil, err
@@ -73,12 +80,13 @@ func GetAssistantChatCompletions(asstName string, msg string, stream bool) (*mod
7380
return resp, nil
7481
}
7582

76-
func PostAndStreamChatResponse[B any](baseUrl string, path string, body B) (*models.ChatCompletionModel, error) {
83+
func PostAndStreamChatResponse[B any](baseUrl string, path string, body B, spinner *spinner.Spinner) (*models.ChatCompletionModel, error) {
7784
resp, err := network.RequestWithBody[B](baseUrl, path, http.MethodPost, body)
7885
if err != nil {
7986
return nil, err
8087
}
8188
defer resp.Body.Close()
89+
spinner.Stop()
8290

8391
var completeResponse string
8492
var id string

0 commit comments

Comments
 (0)