From 71ff6e6adfe2315e3cf06d7c562a2da2fb2e824c Mon Sep 17 00:00:00 2001 From: sudipnext Date: Tue, 29 Jul 2025 11:31:43 +0545 Subject: [PATCH] fix(images): return correct image path after generation (a classic SQLAlchemy "detached instance" bug by making sure to access ORM attributes while the session is still open). -update Pixabay API to default to per_page3 --- servers/fastapi/api/v1/ppt/endpoints/images.py | 3 ++- servers/fastapi/services/image_generation_service.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/servers/fastapi/api/v1/ppt/endpoints/images.py b/servers/fastapi/api/v1/ppt/endpoints/images.py index 826f5436..79d1a38d 100644 --- a/servers/fastapi/api/v1/ppt/endpoints/images.py +++ b/servers/fastapi/api/v1/ppt/endpoints/images.py @@ -24,8 +24,9 @@ async def generate_image(prompt: str): with get_sql_session() as sql_session: sql_session.add(image) sql_session.commit() + image_path = image.path - return image.path + return image_path @IMAGES_ROUTER.get("/generated", response_model=List[ImageAsset]) diff --git a/servers/fastapi/services/image_generation_service.py b/servers/fastapi/services/image_generation_service.py index 4299ced1..0d6e1358 100644 --- a/servers/fastapi/services/image_generation_service.py +++ b/servers/fastapi/services/image_generation_service.py @@ -123,7 +123,7 @@ class ImageGenerationService: async def get_image_from_pixabay(self, prompt: str) -> str: async with aiohttp.ClientSession() as session: response = await session.get( - f"https://pixabay.com/api/?key={get_pixabay_api_key_env()}&q={prompt}&image_type=photo&per_page=1" + f"https://pixabay.com/api/?key={get_pixabay_api_key_env()}&q={prompt}&image_type=photo&per_page=3" ) data = await response.json() image_url = data["hits"][0]["largeImageURL"]