Commit Graph
2 Commits
Author SHA1 Message Date
yetoneandggbdpq 7301c070f0 gateway: /v1/images/edits reads and forwards OpenAI's markup layer (#5364)
OpenAI's images edit takes `markup`, a transparent PNG laid over the
first image to steer the edit (JSON image_url, or a multipart file part;
never beside a mask). magpie read only the mask: a JSON markup stopped in
drawing.Extra, a multipart one was dropped, and neither the ChatGPT
backend's JSON edit nor the plain multipart edit carried it, so an edit
with a markup came back 200 with the layer left out (#5364, kongjianguan,
with the probe and the three places).

drawing has a Markup beside Mask, read from JSON (markup.image_url) and
from a multipart `markup` part, and sent where the mask is: as
{"image_url": data URL} on the ChatGPT/SenseNova JSON edit and as its own
part on the multipart edit. A markup that can't be read, or one sent with
a mask, is a 400 before anything is asked. OpenRouter, Volcengine Ark and
DashScope, which turn a mask away, turn a markup away by name too.

Patch from ggbdpq (mbox sha256 b591c6ad499789c5, matches the issue).
Changed in review:
- "markup" joins drawingRead, so it no longer also rides Extra; on Ark
  the raw field went out as an Ark field.
- Ark and DashScope refuse a markup as they refuse a mask; the patch
  refused it on OpenRouter only.
- A mask with a markup is a 400 (OpenAI's docs: "Cannot be combined
  with mask").
- Tests rewritten: the patch's broken-markup test posted to a server
  with no "art" provider, so it would have been a 400 for the unknown
  model with or without the fix; the Codex test kept its upstream in a
  package global. They now check the bytes that reach the vendor, the
  multipart-in case, the mask clash and the three refusals.

Run on mote (-tags nogui, the package's TestMain sandbox):
- TestCodexEditSendsTheMarkup, TestEditSendsTheMarkup/{json,multipart},
  TestEditWithAMarkupItCantSendIsRefused/{not base64,beside a mask},
  TestMarkupRefusedWhereNoLayerIsTaken: ok.
- Broken by hand: draw.go, draw_dashscope.go, draw_volcengine.go back to
  cff530079 (Markup field kept so the tests build): all four FAIL ("the
  ChatGPT edit's markup is \"\"", "kept as an extra field too", "the
  markup layer never reached the vendor whole", "not base64: 200, want
  400", "beside a mask: 200", "Ark: <nil>", "DashScope: <nil>",
  "OpenRouter: 502 ... want 400").
- -race -run 'Draw|Image|Edit|Ark|DashScope|OpenRouter|Markup|Mask|Volc|
  Seedream|ModelScope|SenseNova' ./internal/gateway: ok 108s.
- go vet -tags nogui, GOOS=linux go vet -tags nogui, GOOS=windows go vet
  of ./internal/gateway: clean. gofmt -l: clean.

Not tried: a real ChatGPT account's gpt-image edit with a markup (none
here), so whether that backend applies the field, or refuses it, is
unknown; OpenAI's public docs list markup for GPT Image 2.5. Not
changed: routes that drop a mask today (Grok, ModelScope, chat-model and
Gemini draws, WorkBuddy) drop a markup the same way. The full suite is
run after the push.

Reported-by: kongjianguan
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 11:12:12 +08:00
yetone 03f3e1528b gateway: Qwen-Image and Wan 2.7 image models draw on DashScope's own API, so qwen-image-3.0-pro no longer draws nothing (judi0713)
judi0713 on Discord (v0.1.2288): qwen-image-3.0-pro draws when called
directly, but through magpie answers 502 "qwen-image-3.0-pro drew
nothing". DashScope documents its Qwen-Image and Wan 2.7 image models on
its own multimodal-generation API only (docs.qwencloud.com "Qwen-Image
text-to-image", and the Token Plan's "Integrate multimodal generation"):
a POST to <host>/api/v1/services/aigc/multimodal-generation/generation,
answered with the images at output.choices[].message.content[].image.
magpie sent them to the OpenAI images API at /compatible-mode/v1 and, on
its 404, to chat completions, whose answer holds no image it reads. Which
of the two answered the reporter is not seen from here.

Now, on a DashScope provider (dashScope(): Bailian, Model Studio, the Qwen
AI platform and Qwen Cloud, pay as you go and Token Plan, by preset or
host) a model named qwen-image* or wan2.7-image* draws there
(draw_dashscope.go, from drawImages):
- the prompt and any input images (data URLs) as one user message,
  parameters watermark false, n when over 1, size as W*H;
- every image of every choice is read; with none, the error says what
  DashScope said (message and code), the model's text, or the
  finish_reason;
- a mask or a ratio size is a 400 saying what to send instead, with no
  request made.
The root is the provider's Chat (or Anthropic) base cut at
/compatible-mode/, /apps/ or /api/v1. Every other provider and model is
unchanged (TestDashScopeDrawsScoped). /v1/images/generations and
/v1/images/edits both go through drawImages, and magpie's generate_image
MCP draws through those two, so all three are covered.

The fixtures are the documented response bytes, not a live answer.

Run (mote, at b06df2557 on 3e5aa1151):
- gofmt -l: clean.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui ./... -timeout 45m -count=1: every package ok
  (gateway 745s) except two reds already filed, in code this doesn't
  touch: internal/gui TestColdTurnsTaken (#4510) and internal/proc
  TestNoCommandBypassesProc (claudetui/child_unix.go, #4491).

Broken by hand: drawImages' dispatch made `if false && dashScopeDraws`:
TestDashScopeDrawsOnItsOwnAPI, TestDashScopeEdits and TestDashScopeSaysWhy
go red (the fake answers 404 off its native path).

Not tried:
- No real Qwen Cloud or DashScope account: no request reached Alibaba.
- The chat fallback's parse of a {"image": ...} part is unchanged.
- Older Wan text-to-image models (an asynchronous task API) and video
  are left as they were.
- No GUI change, so no GUI run.
2026-10-31 10:15:15 +08:00