From 2665f9364df21b6ee6ab02f96c8ce3f538592293 Mon Sep 17 00:00:00 2001 From: Slipstream Date: Mon, 28 Apr 2025 00:49:04 -0600 Subject: [PATCH] a --- cogs/profile_updater_cog.py | 25 ++++++++++++++++++----- gurt/api.py | 40 ++++++++++++++++++++++++++++++++++++- requirements.txt | 4 +++- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/cogs/profile_updater_cog.py b/cogs/profile_updater_cog.py index 1249dc8..277e1d4 100644 --- a/cogs/profile_updater_cog.py +++ b/cogs/profile_updater_cog.py @@ -280,12 +280,27 @@ Review your current profile state (provided below) and decide if you want to mak {"type": "text", "text": f"{state_summary}{image_prompt_part}\n\nReview your current profile state. Decide if you want to change your avatar, bio, roles, or activity status based on your personality, mood, and interests. If yes, specify the changes in the JSON. If not, set 'should_update' to false.\n\n**CRITICAL: Respond ONLY with a valid JSON object matching the required schema.**"} ]} ] - # Add image data if available and model supports it + # Add image data if available if current_state.get('avatar_image_data'): - # Convert to Vertex AI format if needed (get_internal_ai_json_response handles this) - # prompt_messages[-1]["content"].append(Part.from_data(...)) # Example - print("ProfileUpdaterTask: Added current avatar image to AI prompt.") - + try: + # Extract mime type and base64 data from the data URI string + data_uri = current_state['avatar_image_data'] + header, encoded = data_uri.split(',', 1) + mime_type = header.split(';')[0].split(':')[1] + # Append the image data part to the user message content list + prompt_messages[-1]["content"].append({ + "type": "image_data", # Use a custom type marker for now + "mime_type": mime_type, + "data": encoded # The raw base64 string + }) + print("ProfileUpdaterTask: Added current avatar image data to AI prompt.") + except Exception as img_err: + print(f"ProfileUpdaterTask: Failed to process/add avatar image data: {img_err}") + # Optionally add a text note about the failure + prompt_messages[-1]["content"].append({ + "type": "text", + "text": "\n(System Note: Failed to include current avatar image in prompt.)" + }) try: # Use the imported get_internal_ai_json_response function diff --git a/gurt/api.py b/gurt/api.py index 74c864b..b1a03ba 100644 --- a/gurt/api.py +++ b/gurt/api.py @@ -982,7 +982,45 @@ async def get_internal_ai_json_response( continue # Skip adding system messages to contents list elif role == "assistant": role = "model" - contents.append(Content(role=role, parts=[Part.from_text(content_text)])) + + # --- Process content (string or list) --- + content_value = msg.get("content") + message_parts: List[Part] = [] # Initialize list to hold parts for this message + + if isinstance(content_value, str): + # Handle simple string content + message_parts.append(Part.from_text(content_value)) + elif isinstance(content_value, list): + # Handle list content (e.g., multimodal from ProfileUpdater) + for part_data in content_value: + part_type = part_data.get("type") + if part_type == "text": + text = part_data.get("text", "") + message_parts.append(Part.from_text(text)) + elif part_type == "image_data": + mime_type = part_data.get("mime_type") + base64_data = part_data.get("data") + if mime_type and base64_data: + try: + image_bytes = base64.b64decode(base64_data) + message_parts.append(Part.from_data(data=image_bytes, mime_type=mime_type)) + except Exception as decode_err: + print(f"Error decoding/adding image part in get_internal_ai_json_response: {decode_err}") + # Optionally add a placeholder text part indicating failure + message_parts.append(Part.from_text("(System Note: Failed to process an image part)")) + else: + print("Warning: image_data part missing mime_type or data.") + else: + print(f"Warning: Unknown part type '{part_type}' in internal prompt message.") + else: + print(f"Warning: Unexpected content type '{type(content_value)}' in internal prompt message.") + + # Add the content object if parts were generated + if message_parts: + contents.append(Content(role=role, parts=message_parts)) + else: + print(f"Warning: No parts generated for message role '{role}'.") + # Add the critical JSON instruction to the last user message or as a new user message json_instruction_content = ( diff --git a/requirements.txt b/requirements.txt index f032c13..c3b4be7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,6 @@ lxml PyNaCl discord-webhook openrouter -google-cloud-vertexai +google-cloud-vertexai==1.53.0 +protobuf==3.20.3 +proto-plus==1.23.0