GenerateContentResponse.text may not return all the response info
Closed this issue · 4 comments
It looks like GenerateContentResponse.text
just returns the text from the first Candidate
in the candidates list, and from that candidate, the first TextPart
in the parts list. I don't know about the guarantees wrt what the server returns, but it would probably be good to concatenate the returned candidates and parts (or, not offer a simplified API?).
When I looked at the implementations in the other languages this was the behavior I saw.
Looking back through the design docs I think the intention may have been to throw if there are multiple candidates, but I don't recall if that was the behavior I saw in the other implementations.
I have been printing the responses I'm getting back for a local tool I'm running, and (anecdotally) haven't seen more than one candidate.
You can also enforce a single candidate by setting the GenerationConfig.candidateCount
when constructing the model or making a request. https://pub.dev/documentation/google_generative_ai/latest/google_generative_ai/GenerationConfig/candidateCount.html
I think the main thing we can do is expand the docs to mention this.