Support OpenClaw image responses
This commit is contained in:
@@ -2355,6 +2355,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"invalid_request_error", "invalid_seed")
|
||||
return
|
||||
|
||||
response_format_explicit = "response_format" in data
|
||||
response_format = data.get("response_format", "url")
|
||||
if response_format not in ("url", "b64_json"):
|
||||
self._send_error(400, "'response_format' muss 'url' oder 'b64_json' sein",
|
||||
@@ -2379,9 +2380,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
for filename in results:
|
||||
path = os.path.join(IMAGE_DIR, filename)
|
||||
item: dict = {"url": f"{host}/images/{filename}", "b64_json": None}
|
||||
if response_format == "b64_json":
|
||||
# OpenClaw's OpenAI-compatible image parser requires b64_json but
|
||||
# does not send response_format. Keep the URL for existing clients
|
||||
# and add inline image data only when the format was omitted.
|
||||
if response_format == "b64_json" or not response_format_explicit:
|
||||
with open(path, "rb") as f:
|
||||
item["b64_json"] = base64.b64encode(f.read()).decode()
|
||||
if response_format == "b64_json":
|
||||
item["url"] = None
|
||||
items.append(item)
|
||||
payload: dict = {"created": int(time.time()), "data": items}
|
||||
|
||||
Reference in New Issue
Block a user