chore: #975 check choices available

This commit is contained in:
Eugen Eisler 2024-09-18 14:08:09 +02:00
parent d2e2a6537e
commit c2a15f6aa1

View File

@ -82,7 +82,12 @@ func (o *Client) SendStream(
for { for {
var response openai.ChatCompletionStreamResponse var response openai.ChatCompletionStreamResponse
if response, err = stream.Recv(); err == nil { if response, err = stream.Recv(); err == nil {
if len(response.Choices) > 0 {
channel <- response.Choices[0].Delta.Content channel <- response.Choices[0].Delta.Content
} else {
fmt.Printf("No response (choices) from stream\n")
break
}
} else if errors.Is(err, io.EOF) { } else if errors.Is(err, io.EOF) {
channel <- "\n" channel <- "\n"
close(channel) close(channel)