From 23cb9a9ee8ea9430cf20426ae605fd4b4acef976 Mon Sep 17 00:00:00 2001 From: Eugen Eisler Date: Wed, 18 Sep 2024 14:19:00 +0200 Subject: [PATCH] chore: #975 check choices available --- vendors/openai/openai.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vendors/openai/openai.go b/vendors/openai/openai.go index 88997f4..bb81b90 100644 --- a/vendors/openai/openai.go +++ b/vendors/openai/openai.go @@ -85,7 +85,8 @@ func (o *Client) SendStream( if len(response.Choices) > 0 { channel <- response.Choices[0].Delta.Content } else { - fmt.Printf("No response (choices) from stream\n") + channel <- "\n" + close(channel) break } } else if errors.Is(err, io.EOF) { @@ -108,7 +109,9 @@ func (o *Client) Send(ctx context.Context, msgs []*common.Message, opts *common. if resp, err = o.ApiClient.CreateChatCompletion(ctx, req); err != nil { return } - ret = resp.Choices[0].Message.Content + if len(resp.Choices) > 0 { + ret = resp.Choices[0].Message.Content + } return }