@@ -412,13 +412,15 @@ def parts(self):
412
412
"""
413
413
candidates = self .candidates
414
414
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
+ )
417
419
if self .prompt_feedback :
418
420
raise ValueError (
419
- msg +
420
- " \n This appears to be caused by a blocked prompt, "
421
- f"see `response.prompt_feedback`: { self . prompt_feedback } " )
421
+ msg + " \n This appears to be caused by a blocked prompt, "
422
+ f"see `response.prompt_feedback`: { self . prompt_feedback } "
423
+ )
422
424
else :
423
425
raise ValueError (msg )
424
426
@@ -444,11 +446,13 @@ def text(self):
444
446
fr = candidate .finish_reason
445
447
FinishReason = protos .Candidate .FinishReason
446
448
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
+ )
450
454
if candidate .finish_message :
451
- msg += " The `finish_message` is \ " {candidate.finish_message}\" ."
455
+ msg += ' The `finish_message` is "{candidate.finish_message}".'
452
456
453
457
if fr is FinishReason .FINISH_REASON_UNSPECIFIED :
454
458
raise ValueError (msg )
@@ -457,10 +461,14 @@ def text(self):
457
461
elif fr is FinishReason .MAX_TOKENS :
458
462
raise ValueError (msg )
459
463
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
+ )
462
468
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
+ )
464
472
elif fr is FinishReason .LANGUAGE :
465
473
raise ValueError (msg + " Meaning the response was using an unsupported language." )
466
474
elif fr is FinishReason .OTHER :
@@ -473,11 +481,11 @@ def text(self):
473
481
raise ValueError (msg + " SPII - Sensitive Personally Identifiable Information." )
474
482
elif fr is FinishReason .MALFORMED_FUNCTION_CALL :
475
483
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. "
478
485
"Setting the "
479
486
"[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
+ )
481
489
else :
482
490
raise ValueError (msg )
483
491
0 commit comments