in google/generativeai/types/generation_types.py [0:0]
def parts(self):
"""A quick accessor equivalent to `self.candidates[0].content.parts`
Raises:
ValueError: If the candidate list does not contain exactly one candidate.
"""
candidates = self.candidates
if not candidates:
msg = (
"Invalid operation: The `response.parts` quick accessor requires a single candidate, "
"but but `response.candidates` is empty."
)
if self.prompt_feedback:
raise ValueError(
msg + "\nThis appears to be caused by a blocked prompt, "
f"see `response.prompt_feedback`: {self.prompt_feedback}"
)
else:
raise ValueError(msg)
if len(candidates) > 1:
raise ValueError(
"Invalid operation: The `response.parts` quick accessor retrieves the parts for a single candidate. "
"This response contains multiple candidates, please use `result.candidates[index].text`."
)
parts = candidates[0].content.parts
return parts