catch exception

This commit is contained in:
xds
2026-02-04 18:23:36 +03:00
parent 53b2bce1b2
commit bf8396a790
5 changed files with 25 additions and 9 deletions

3
adapters/Exception.py Normal file
View File

@@ -0,0 +1,3 @@
class GoogleGenerationException(Exception):
message: str
pass

View File

@@ -7,6 +7,7 @@ from PIL import Image
from google import genai
from google.genai import types
from adapters.Exception import GoogleGenerationException
from models.enums import AspectRatios, Quality
logger = logging.getLogger(__name__)
@@ -85,6 +86,8 @@ class GoogleAdapter:
),
)
)
if response.parts is None and response.candidates[0].finish_reason is not None:
raise GoogleGenerationException(f"Generation blocked in cause of {response.candidates[0].finish_reason.value}")
generated_images = []