-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
AgentScope Version: 1.0.16dev
Description:
When a local image file has no extension (e.g., /app/downloads/download), _to_openai_image_url raises:
TypeError: "/app/downloads/download" should end with (.png, .jpg, .jpeg, .gif, .webp).
This happens when:
- Downloading images from URLs without file extension in the path (e.g., QQ multimedia URLs like
https://multimedia.nt.qq.com.cn/download?appid=...&rkey=...) - The downloaded file has no extension
Reproduction:
# Download an image from a URL without extension
import urllib.request
urllib.request.urlretrieve("https://example.com/download?token=xxx", "/tmp/download")
# File saved as /tmp/download (no extension)
# Then try to use it in a message
# _to_openai_image_url("/tmp/download") raises TypeErrorSuggested Fix:
Use imghdr to detect file type when extension is missing:
import imghdr
# In _to_openai_image_url, when local file has no extension:
detected_type = imghdr.what(url)
if detected_type in ("png", "jpeg", "gif", "webp"):
with open(url, "rb") as f:
base64_image = base64.b64encode(f.read()).decode("utf-8")
mime_type = f"image/{detected_type}"
return f"data:{mime_type};base64,{base64_image}"Related: PR #1066 (URLs with query parameters), PR #1284 (file:// URI handling)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels