Skip to content

Commit

Permalink
Merge pull request #17 from tkawachi/issue-16
Browse files Browse the repository at this point in the history
Add error handling for empty response in AI chatbot
  • Loading branch information
mergify[bot] authored Mar 11, 2023
2 parents b4b23db + a0e4bee commit 690f23c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aichat.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func streamCompletion(client *gogpt.Client, request gogpt.ChatCompletionRequest,
if err != nil {
return fmt.Errorf("stream recv: %w", err)
}
if len(response.Choices) == 0 {
return fmt.Errorf("no choices returned")
}
_, err = fmt.Fprint(out, response.Choices[0].Delta.Content)
if err != nil {
return err
Expand Down

0 comments on commit 690f23c

Please sign in to comment.