Skip to content

Commit 501f5ef

Browse files
committed
Format
Change-Id: Iee130a7e58f2cfbc1001808ac892f119338626eb
1 parent 5c96b9b commit 501f5ef

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

google/generativeai/types/generation_types.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,15 @@ def parts(self):
412412
"""
413413
candidates = self.candidates
414414
if not candidates:
415-
msg = ("Invalid operation: The `response.parts` quick accessor requires a single candidate, "
416-
"but but `response.candidates` is empty.")
415+
msg = (
416+
"Invalid operation: The `response.parts` quick accessor requires a single candidate, "
417+
"but but `response.candidates` is empty."
418+
)
417419
if self.prompt_feedback:
418420
raise ValueError(
419-
msg +
420-
"\nThis appears to be caused by a blocked prompt, "
421-
f"see `response.prompt_feedback`: {self.prompt_feedback}")
421+
msg + "\nThis appears to be caused by a blocked prompt, "
422+
f"see `response.prompt_feedback`: {self.prompt_feedback}"
423+
)
422424
else:
423425
raise ValueError(msg)
424426

@@ -444,11 +446,13 @@ def text(self):
444446
fr = candidate.finish_reason
445447
FinishReason = protos.Candidate.FinishReason
446448

447-
msg=("Invalid operation: The `response.text` quick accessor requires the response to contain a valid "
448-
"`Part`, but none were returned. The candidate's "
449-
f"[finish_reason](https://ai.google.dev/api/generate-content#finishreason) is {fr}.")
449+
msg = (
450+
"Invalid operation: The `response.text` quick accessor requires the response to contain a valid "
451+
"`Part`, but none were returned. The candidate's "
452+
f"[finish_reason](https://ai.google.dev/api/generate-content#finishreason) is {fr}."
453+
)
450454
if candidate.finish_message:
451-
msg += "The `finish_message` is \"{candidate.finish_message}\"."
455+
msg += 'The `finish_message` is "{candidate.finish_message}".'
452456

453457
if fr is FinishReason.FINISH_REASON_UNSPECIFIED:
454458
raise ValueError(msg)
@@ -457,10 +461,14 @@ def text(self):
457461
elif fr is FinishReason.MAX_TOKENS:
458462
raise ValueError(msg)
459463
elif fr is FinishReason.SAFETY:
460-
raise ValueError(msg +
461-
f" The candidate's safety_ratings are: {candidate.safety_ratings}.", candidate.safety_ratings)
464+
raise ValueError(
465+
msg + f" The candidate's safety_ratings are: {candidate.safety_ratings}.",
466+
candidate.safety_ratings,
467+
)
462468
elif fr is FinishReason.RECITATION:
463-
raise ValueError(msg + " Meaning that the model was reciting from copyrighted material.")
469+
raise ValueError(
470+
msg + " Meaning that the model was reciting from copyrighted material."
471+
)
464472
elif fr is FinishReason.LANGUAGE:
465473
raise ValueError(msg + " Meaning the response was using an unsupported language.")
466474
elif fr is FinishReason.OTHER:
@@ -473,11 +481,11 @@ def text(self):
473481
raise ValueError(msg + " SPII - Sensitive Personally Identifiable Information.")
474482
elif fr is FinishReason.MALFORMED_FUNCTION_CALL:
475483
raise ValueError(
476-
msg +
477-
" Meaning that model generated a `FunctionCall` that was invalid. "
484+
msg + " Meaning that model generated a `FunctionCall` that was invalid. "
478485
"Setting the "
479486
"[Function calling mode](https://ai.google.dev/gemini-api/docs/function-calling#function_calling_mode) "
480-
"to `ANY` can fix this because it enables constrained decoding.")
487+
"to `ANY` can fix this because it enables constrained decoding."
488+
)
481489
else:
482490
raise ValueError(msg)
483491

0 commit comments

Comments
 (0)