a
This commit is contained in:
parent
587a23b5be
commit
2665f9364d
@ -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
|
||||
|
40
gurt/api.py
40
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 = (
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user