This commit is contained in:
xds
2026-02-12 18:41:01 +03:00
parent dcab238d3e
commit 977cab92f8
3 changed files with 15 additions and 3 deletions

View File

@@ -105,9 +105,21 @@ class GoogleAdapter:
if response.usage_metadata: if response.usage_metadata:
token_usage = response.usage_metadata.total_token_count token_usage = response.usage_metadata.total_token_count
if response.parts is None and response.candidates[0].finish_reason is not None: # Check prompt-level block (e.g. PROHIBITED_CONTENT) — no candidates in this case
raise GoogleGenerationException(f"Generation blocked in cause of {response.candidates[0].finish_reason.value}") if response.prompt_feedback and response.prompt_feedback.block_reason:
raise GoogleGenerationException(
f"Generation blocked at prompt level: {response.prompt_feedback.block_reason.value}"
)
# Check candidate-level block
if response.parts is None:
response_reason = (
response.candidates[0].finish_reason
if response.candidates and len(response.candidates) > 0
else "Unknown"
)
raise GoogleGenerationException(f"Generation blocked: {response_reason}")
generated_images = [] generated_images = []