feat: Implement image thumbnail generation, storage, and API endpoints for assets, including a regeneration utility.
This commit is contained in:
Binary file not shown.
@@ -66,7 +66,7 @@ class GenerationService:
|
||||
async def ask_prompt_assistant(self, prompt: str, assets: List[str] = None) -> str:
|
||||
future_prompt = """You are an prompt-assistant. You improving user-entered prompts for image generation. User may upload reference image too.
|
||||
I will provide sources prompt entered by user. Understand user needs and generate best variation of prompt.
|
||||
ANSWER ONLY PROMPT STRING!!! USER_ENTERED_PROMPT:"""
|
||||
ANSWER ONLY PROMPT STRING!!! USER_ENTERED_PROMPT: """
|
||||
future_prompt += prompt
|
||||
assets_data = []
|
||||
if assets is not None:
|
||||
@@ -88,7 +88,7 @@ class GenerationService:
|
||||
|
||||
async def get_generations(self, character_id: Optional[str] = None, limit: int = 10, offset: int = 0) -> List[
|
||||
Generation]:
|
||||
return await self.dao.generations.get_generations(limit=limit, offset=offset)
|
||||
return await self.dao.generations.get_generations(character_id = character_id,limit=limit, offset=offset)
|
||||
|
||||
async def get_generation(self, generation_id: str) -> Optional[GenerationResponse]:
|
||||
gen = await self.dao.generations.get_generation(generation_id)
|
||||
@@ -162,7 +162,7 @@ class GenerationService:
|
||||
for asset in reference_assets
|
||||
if asset.data is not None and asset.type == AssetType.IMAGE
|
||||
)
|
||||
generation_prompt+=f"PROMPT: {generation.prompt}"
|
||||
generation_prompt+=f" PROMPT: {generation.prompt}"
|
||||
logger.info(f"Final generation prompt assembled. Length: {len(generation_prompt)}. Media count: {len(media_group_bytes)}")
|
||||
|
||||
# 3. Запускаем процесс генерации и симуляцию прогресса
|
||||
@@ -209,11 +209,19 @@ class GenerationService:
|
||||
created_assets: List[Asset] = []
|
||||
|
||||
for idx, img_bytes in enumerate(generated_bytes_list):
|
||||
# Generate thumbnail
|
||||
thumbnail_bytes = None
|
||||
# Assuming AssetType.IMAGE since we are in generated_bytes_list which are images usually
|
||||
# Or use explicit check if we have distinct types in list (not currently)
|
||||
from utils.image_utils import create_thumbnail
|
||||
thumbnail_bytes = await asyncio.to_thread(create_thumbnail, img_bytes)
|
||||
|
||||
new_asset = Asset(
|
||||
name=f"Generated_{generation.linked_character_id}_{random.randint(1000, 9999)}",
|
||||
type=AssetType.IMAGE,
|
||||
linked_char_id=generation.linked_character_id, # Если генерация привязана к персонажу
|
||||
data=img_bytes,
|
||||
thumbnail=thumbnail_bytes
|
||||
# Остальные поля заполнятся дефолтными значениями (created_at)
|
||||
)
|
||||
|
||||
@@ -236,6 +244,8 @@ class GenerationService:
|
||||
end_time = datetime.now()
|
||||
generation.execution_time_seconds = (end_time - start_time).total_seconds()
|
||||
|
||||
logger.info(f"DEBUG: Saving generation {generation.id}. Metrics: api_exec={generation.api_execution_time_seconds}, tokens={generation.token_usage}, exec={generation.execution_time_seconds}")
|
||||
|
||||
await self.dao.generations.update_generation(generation)
|
||||
logger.info(f"Generation {generation.id} completed successfully. {len(created_assets)} assets created. Total Time: {generation.execution_time_seconds:.2f}s")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user