Skip to content

Commit bdd4817

Browse files
Ark-kuncopybara-github
authored andcommitted
chore: GenAI - Improve GenerationResponse.text error message when there are no candidates
PiperOrigin-RevId: 617066254
1 parent f0086df commit bdd4817

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

vertexai/generative_models/_generative_models.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,12 @@ def candidates(self) -> List["Candidate"]:
14041404
@property
14051405
def text(self) -> str:
14061406
if len(self.candidates) > 1:
1407-
raise ValueError("Multiple candidates are not supported")
1407+
raise ValueError(
1408+
"The response has multiple candidates."
1409+
" Use `response.candidate[i].text` to get text of a particular candidate."
1410+
)
1411+
if not self.candidates:
1412+
raise ValueError("Response has no candidates (and no text).")
14081413
return self.candidates[0].text
14091414

14101415

0 commit comments

Comments
 (0)