diff --git a/adapters/__pycache__/google_adapter.cpython-313.pyc b/adapters/__pycache__/google_adapter.cpython-313.pyc index e61c572..221010d 100644 Binary files a/adapters/__pycache__/google_adapter.cpython-313.pyc and b/adapters/__pycache__/google_adapter.cpython-313.pyc differ diff --git a/adapters/google_adapter.py b/adapters/google_adapter.py index 7298066..d40d60f 100644 --- a/adapters/google_adapter.py +++ b/adapters/google_adapter.py @@ -131,9 +131,17 @@ class GoogleAdapter: else: logger.warning("No images text generated from parts") + input_tokens = 0 + output_tokens = 0 + if response.usage_metadata: + input_tokens = response.usage_metadata.prompt_token_count + output_tokens = response.usage_metadata.candidates_token_count + metrics = { "api_execution_time_seconds": api_duration, - "token_usage": token_usage + "token_usage": token_usage, + "input_token_usage": input_tokens, + "output_token_usage": output_tokens } return generated_images, metrics diff --git a/api/models/GenerationRequest.py b/api/models/GenerationRequest.py index 06f8a96..02e6436 100644 --- a/api/models/GenerationRequest.py +++ b/api/models/GenerationRequest.py @@ -14,6 +14,7 @@ class GenerationRequest(BaseModel): quality: Quality = Quality.ONEK prompt: str telegram_id: Optional[int] = None + use_profile_image: bool = True assets_list: List[str] @@ -32,6 +33,8 @@ class GenerationResponse(BaseModel): execution_time_seconds: Optional[float] = None api_execution_time_seconds: Optional[float] = None token_usage: Optional[int] = None + input_token_usage: Optional[int] = None + output_token_usage: Optional[int] = None progress: int = 0 created_at: datetime = datetime.now(UTC) updated_at: datetime = datetime.now(UTC) diff --git a/api/models/__pycache__/GenerationRequest.cpython-313.pyc b/api/models/__pycache__/GenerationRequest.cpython-313.pyc index ff498b0..dce7843 100644 Binary files a/api/models/__pycache__/GenerationRequest.cpython-313.pyc and b/api/models/__pycache__/GenerationRequest.cpython-313.pyc differ diff --git a/api/service/__pycache__/generation_service.cpython-313.pyc b/api/service/__pycache__/generation_service.cpython-313.pyc index 07a5cf1..cd01f61 100644 Binary files a/api/service/__pycache__/generation_service.cpython-313.pyc and b/api/service/__pycache__/generation_service.cpython-313.pyc differ diff --git a/api/service/generation_service.py b/api/service/generation_service.py index be67fa9..705671c 100644 --- a/api/service/generation_service.py +++ b/api/service/generation_service.py @@ -154,7 +154,8 @@ class GenerationService: char_info = await self.dao.chars.get_character(generation.linked_character_id, with_image_data=True) if char_info is None: raise Exception(f"Character ID {generation.linked_character_id} not found") - media_group_bytes.append(char_info.character_image_data) + if generation.use_profile_image: + media_group_bytes.append(char_info.character_image_data) generation_prompt = f"""You are creating image for {char_info.character_bio}""" reference_assets = await self.dao.assets.get_assets_by_ids(generation.assets_list) @@ -182,9 +183,12 @@ class GenerationService: gemini=self.gemini ) + # Update metrics from API (Common for both) # Update metrics from API (Common for both) generation.api_execution_time_seconds = metrics.get("api_execution_time_seconds") generation.token_usage = metrics.get("token_usage") + generation.input_token_usage = metrics.get("input_token_usage") + generation.output_token_usage = metrics.get("output_token_usage") except GoogleGenerationException as e: generation.status = GenerationStatus.FAILED @@ -247,7 +251,7 @@ 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}") + logger.info(f"DEBUG: Saving generation {generation.id}. Metrics: api_exec={generation.api_execution_time_seconds}, tokens={generation.token_usage}, in_tokens={generation.input_token_usage}, out_tokens={generation.output_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") diff --git a/models/Generation.py b/models/Generation.py index 9bd313b..2cb018b 100644 --- a/models/Generation.py +++ b/models/Generation.py @@ -19,6 +19,7 @@ class Generation(BaseModel): failed_reason: Optional[str] = None linked_character_id: Optional[str] = None telegram_id: Optional[int] = None + use_profile_image: bool = True aspect_ratio: AspectRatios quality: Quality prompt: str @@ -29,6 +30,8 @@ class Generation(BaseModel): execution_time_seconds: Optional[float] = None api_execution_time_seconds: Optional[float] = None token_usage: Optional[int] = None + input_token_usage: Optional[int] = None + output_token_usage: Optional[int] = None created_at: datetime = Field(default_factory=lambda: datetime.now(UTC)) updated_at: datetime = Field(default_factory=lambda: datetime.now(UTC)) diff --git a/models/__pycache__/Generation.cpython-313.pyc b/models/__pycache__/Generation.cpython-313.pyc index d31ee70..cc4f421 100644 Binary files a/models/__pycache__/Generation.cpython-313.pyc and b/models/__pycache__/Generation.cpython-313.pyc differ