video: Seedance takes a last frame and Ark's own fields through /v1/videos
/v1/videos read OpenAI's request into Ark's content-generation body but left out the last frame (last_frame, which magpie reads for MiniMax), and dropped every field OpenAI's API doesn't have, so a caller in OpenAI's shape couldn't turn off Seedance's audio, fix a seed or ask for an adaptive ratio (axelburks on Discord asked that the OpenAI shape be converted to the vendor's). volcengineVideoBody now sends last_frame as an image_url item with role last_frame, and passes the request's other fields on as sent (masked as the prompt is, as for a provider's own videos API). A multipart form's "false" or "42" goes as false or 42, as Ark takes them. Run (mote): at a7f31ef46 (this stack on2c90922b0), gofmt -l internal clean, GOOS=linux and GOOS=windows go vet ./... ok; go test -timeout 45m of internal/gateway, imagemcp, browsermcp, cli, davsync, gui, library, settingsapi, tui, agent: all ok but two reds already filed and untouched here: gateway TestCodexPoolSaysTheClientsVersion (#4807) and cli TestEveryRouteHasACommandOrIsNamed (#4826). After rebasing on1490045f5, gateway re-run there (pushed onto253aee08b, whose later commits change only provider/gui Gemini URL defaults; not re-run): gofmt, both vets, and gateway -run Ark|Volcengine|Video|Videomaker| ImageMCP|Draw|Image|Film|MiniMax|Grok plus imagemcp, ok. Broken by hand: arkFilms false for a non-preset Ark key turns TestArkKeyMakesSeedanceVideos red (create 404 at /api/v3/videos, the reported gap); leaving out the last_frame item, or sending multipart strings untyped ("false", "42"), turns TestArkVideoTakesLastFrameAndItsOwnFields red. Not tried: a real Ark account (the fake answers with Ark's captured replies from volcengine_fixtures_test.go); multipart extras against real Ark; the MCP's generate_video has no last_frame argument yet. Siblings filed: #4954 (an OpenAI key's Sora can't make videos), #4955 (Seedance listed as chat models).
This commit is contained in:
@@ -649,9 +649,13 @@ key's video id ends with the key's fingerprint, as a plan key's does, and
|
||||
its poll and download go on that key (`videoAsker` checks the calling key
|
||||
may use it). `volcengineVideoBody` turns OpenAI's request into Ark's: the
|
||||
prompt as a `text` item in `content`, `input_reference` as an `image_url`
|
||||
item with role `first_frame`, `reference_images` as `reference_image`,
|
||||
`seconds` as `duration`, and `size` (WIDTHxHEIGHT) as `ratio` and
|
||||
`resolution`. Ark's `succeeded`/`running`/`failed`/`expired` and its
|
||||
item with role `first_frame`, `last_frame` as `last_frame`,
|
||||
`reference_images` as `reference_image`, `seconds` as `duration`, and
|
||||
`size` (WIDTHxHEIGHT) as `ratio` and `resolution`. The request's fields
|
||||
OpenAI's API doesn't have (Ark's `generate_audio`, `seed`, `camera_fixed`,
|
||||
`watermark`, `ratio: "adaptive"`…) go to Ark as sent, masked as the prompt
|
||||
is; a multipart form's `"false"` or `"42"` goes as `false` or `42`
|
||||
(`TestArkVideoTakesLastFrameAndItsOwnFields`). Ark's `succeeded`/`running`/`failed`/`expired` and its
|
||||
`content.video_url` are read back into OpenAI's video object
|
||||
(`videoObject`), and `/content` fetches that URL (`vendorClient`).
|
||||
`TestArkKeyMakesSeedanceVideos`.
|
||||
|
||||
@@ -483,17 +483,42 @@ func pixelResolution(size string) string {
|
||||
}
|
||||
|
||||
// volcengineVideoBody is f as Ark's content-generation API takes it: text
|
||||
// and images in content, with image roles distinguishing the first frame from
|
||||
// subject references, plus duration, ratio and resolution as separate fields.
|
||||
// and images in content, each image's role saying what it is (the first
|
||||
// frame, the last frame, a subject to draw from), duration, ratio and
|
||||
// resolution as fields of their own, and the request's other fields, which
|
||||
// OpenAI's API doesn't have, as the caller sent them: Ark's own
|
||||
// (generate_audio, seed, camera_fixed, watermark…), which a caller of
|
||||
// OpenAI's shape can only send that way.
|
||||
func volcengineVideoBody(model string, f filming) []byte {
|
||||
content := []map[string]any{{"type": "text", "text": f.Prompt}}
|
||||
frame := func(pic *picture, role string) {
|
||||
content = append(content, map[string]any{"type": "image_url", "image_url": map[string]string{"url": pic.dataURL()}, "role": role})
|
||||
}
|
||||
if f.Start != nil {
|
||||
content = append(content, map[string]any{"type": "image_url", "image_url": map[string]string{"url": f.Start.dataURL()}, "role": "first_frame"})
|
||||
frame(f.Start, "first_frame")
|
||||
}
|
||||
for _, pic := range f.References {
|
||||
content = append(content, map[string]any{"type": "image_url", "image_url": map[string]string{"url": pic.dataURL()}, "role": "reference_image"})
|
||||
if f.End != nil {
|
||||
frame(f.End, "last_frame")
|
||||
}
|
||||
req := map[string]any{"model": model, "content": content}
|
||||
for i := range f.References {
|
||||
frame(&f.References[i], "reference_image")
|
||||
}
|
||||
req := map[string]any{}
|
||||
for k, v := range f.Extra {
|
||||
// a multipart form's fields are text: "false" and "42" are what
|
||||
// Ark takes as false and 42
|
||||
if str, ok := v.(string); ok {
|
||||
var typed any
|
||||
if json.Unmarshal([]byte(str), &typed) == nil {
|
||||
switch typed.(type) {
|
||||
case bool, float64:
|
||||
v = typed
|
||||
}
|
||||
}
|
||||
}
|
||||
req[k] = v
|
||||
}
|
||||
req["model"], req["content"] = model, content
|
||||
if f.Seconds != "" {
|
||||
req["duration"], _ = strconv.Atoi(f.Seconds)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
@@ -133,3 +135,50 @@ func TestArkKeyMakesSeedanceVideos(t *testing.T) {
|
||||
t.Fatalf("sent %s", a.bodies[0])
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAI's videos request, as its SDK sends it (a multipart form, the
|
||||
// first frame a file in input_reference), reaches Seedance as Ark's: the
|
||||
// last frame with role last_frame, and the fields OpenAI's API doesn't
|
||||
// have (Ark's generate_audio, seed) passed on, typed as Ark takes them.
|
||||
func TestArkVideoTakesLastFrameAndItsOwnFields(t *testing.T) {
|
||||
fresh(t)
|
||||
a := newArkKeyVideos(t)
|
||||
was := isArk
|
||||
isArk = func(p provider.Provider) bool { return p.ID == "ark" }
|
||||
t.Cleanup(func() { isArk = was })
|
||||
if err := provider.Save(provider.Provider{ID: "ark", Name: "Volcengine Ark", Chat: a.URL + "/api/v3", Key: "key",
|
||||
Models: []string{"doubao-seedance-1-0-pro-250528"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
mw := multipart.NewWriter(&buf)
|
||||
mw.WriteField("model", "ark/doubao-seedance-1-0-pro-250528")
|
||||
mw.WriteField("prompt", "花开")
|
||||
mw.WriteField("seconds", "5")
|
||||
mw.WriteField("generate_audio", "false")
|
||||
mw.WriteField("seed", "42")
|
||||
mw.WriteField("ratio", "adaptive")
|
||||
for _, k := range []string{"input_reference", "last_frame"} {
|
||||
part, _ := mw.CreateFormFile(k, k+".png")
|
||||
part.Write(pngBytes)
|
||||
}
|
||||
mw.Close()
|
||||
code, _, raw, _ := request(t, New(), http.MethodPost, "/v1/videos", mw.FormDataContentType(), buf.String())
|
||||
if code != 200 {
|
||||
t.Fatalf("create: %d %s", code, raw)
|
||||
}
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
var sent map[string]any
|
||||
if err := json.Unmarshal([]byte(a.bodies[0]), &sent); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
content, _ := sent["content"].([]any)
|
||||
var roles []string
|
||||
for _, c := range content[1:] {
|
||||
roles = append(roles, c.(map[string]any)["role"].(string))
|
||||
}
|
||||
if !slices.Equal(roles, []string{"first_frame", "last_frame"}) || sent["generate_audio"] != false || sent["seed"] != float64(42) || sent["ratio"] != "adaptive" || sent["duration"] != float64(5) {
|
||||
t.Fatalf("sent %s", a.bodies[0])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user