Skip to content

Commit

Permalink
genai: fix panic on nil response (#68)
Browse files Browse the repository at this point in the history
If the model returns no response, treat that as an error.

Fixes #54.
  • Loading branch information
jba authored Mar 12, 2024
1 parent 31e0668 commit eb72633
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions genai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func (iter *GenerateContentResponseIterator) Next() (*GenerateContentResponse, e

func protoToResponse(resp *pb.GenerateContentResponse) (*GenerateContentResponse, error) {
gcp := (GenerateContentResponse{}).fromProto(resp)
if gcp == nil {
return nil, errors.New("empty response from model")
}
// Assume a non-nil PromptFeedback is an error.
// TODO: confirm.
if gcp.PromptFeedback != nil && gcp.PromptFeedback.BlockReason != BlockReasonUnspecified {
Expand Down

0 comments on commit eb72633

Please sign in to comment.