Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a text getter for Candidate #170

Merged
merged 2 commits into from
May 23, 2024
Merged

Add a text getter for Candidate #170

merged 2 commits into from
May 23, 2024

Conversation

natebosch
Copy link
Collaborator

Closes #99

Call out that candidates may be ignored in the doc for
GenerateContentResponse.text.

Add a text getter on Candidate. This is the same logic that was in
the response text getter, applied to an individual candidate.

Refactor the response text implementation to use the candidate field.

Closes #99

Call out that candidates may be ignored in the doc for
`GenerateContentResponse.text`.

Add a `text` getter on `Candidate`. This is the same logic that was in
the response text getter, applied to an individual candidate.

Refactor the response text implementation to use the candidate field.
@natebosch natebosch requested a review from devoncarew May 23, 2024 00:29
/// If there is more than one candidate, all but the first are ignored. See
/// [Candidate.text] to get the text content of candidates other than the
/// first.
String? get text => switch (candidates) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do other language sdks have a similar affordance? It's a nice shorthand for getting results from a response, but may be easy for people to mis-use (to not understand that there could be more than one candidate response).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this API has a coordinated designed across the SDKs. I don't think the text getter on Candidate is as consistent, but every language does have a utility to get the text of the first candidate from a GenerateContentResponse.

@natebosch natebosch merged commit b67b7b3 into main May 23, 2024
7 checks passed
@natebosch natebosch deleted the candidate-text branch May 23, 2024 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GenerateContentResponse.text may not return all the response info
2 participants