fix: Update attachment handling to use types.FileData for URI parts
This commit is contained in:
parent
8f578cfe03
commit
3290b50fbd
@ -932,13 +932,14 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
|
||||
try:
|
||||
# Add the URI part with a cleaned MIME type
|
||||
clean_mime_type = detected_mime_type.split(';')[0] if detected_mime_type else "application/octet-stream"
|
||||
attachment_parts_to_add.append(types.Part(uri=file_url, mime_type=clean_mime_type))
|
||||
print(f"Added URI part for supported attachment: {filename} ({clean_mime_type}) using URL: {file_url}")
|
||||
file_data_obj = types.FileData(mime_type=clean_mime_type, file_uri=file_url)
|
||||
attachment_parts_to_add.append(types.Part(file_data=file_data_obj))
|
||||
print(f"Added FileData part for supported attachment: {filename} ({clean_mime_type}) using URL: {file_url}")
|
||||
except Exception as e:
|
||||
print(f"Error creating URI types.Part for attachment {filename} ({detected_mime_type}): {e}")
|
||||
print(f"Error creating FileData types.Part for attachment {filename} ({detected_mime_type}): {e}")
|
||||
attachment_parts_to_add.append(types.Part(text=f"(System Note: Failed to process attachment '{filename}' - {e})"))
|
||||
else:
|
||||
print(f"Skipping URI part for unsupported attachment: {filename} (Type: {detected_mime_type}, URL: {file_url})")
|
||||
print(f"Skipping FileData part for unsupported attachment: {filename} (Type: {detected_mime_type}, URL: {file_url})")
|
||||
# Text description was already added above
|
||||
|
||||
# Add the collected attachment parts to the existing user message parts
|
||||
|
Loading…
x
Reference in New Issue
Block a user