provider, gateway: Volcengine plans expose their own models by kind (#1265)
This commit is contained in:
@@ -50,7 +50,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
|
||||
- When `logins.json` cannot be decoded as saved accounts, reads keep the accounts read before. Before saving a change, `keepUnreadLogins` copies the original file aside, including valid JSON with invalid account field types, so its credentials can be recovered. If the existing file cannot be read or the backup fails, saving returns the error and leaves the original file unchanged. A missing file can be created normally.
|
||||
- A switched-off provider (`Off`, #163) stays saved. The gateway says it is off instead of saying the model is unknown.
|
||||
- A provider removed or switched off takes its models out of the catalog. [Agent wiring](agent-wiring.md)'s `Reseat` moves agents off them.
|
||||
- A preset marked `NoList` uses its preset model list instead of requesting `/models`, and ignores previously fetched lists, including their protocol and key restrictions, unless the user sets `ModelsURL` or chooses a region marked `Lists`. Volcengine Ark's Coding Plan and Agent Plan use this path: Coding's `/api/coding/v3/models` returns a general Ark catalog instead of the plan's model ids, while Agent's `/api/plan/v3/models` returns 404. Ark's pay-as-you-go region still fetches its own list. [`presets.go`](../../internal/provider/presets.go) defines these choices; `List`, `fetch` and `live` in [`models.go`](../../internal/provider/models.go) apply them when adding, refreshing and reading cached models. `TestVolcengineModelLists` checks that the plans make no list requests, ignore old cached lists and return their preset models; pay-as-you-go and an explicit list URL still make requests.
|
||||
- A preset marked `NoList` uses its preset model list instead of requesting `/models`, and ignores previously fetched lists, including their protocol and key restrictions, unless the user sets `ModelsURL` or chooses a region marked `Lists`. Each region can carry a different list. Volcengine Ark's Coding Plan and Agent Plan use separate preset lists. Both plans include their embedding model separately from agents' chat-model lists; Agent Plan additionally exposes its image- and video-generation models to Settings → Images; Ark itself refuses video generation on Small and Medium Agent Plans, which include it only in the Large and Max tiers. Models magpie does not yet serve (Agent Plan's speech models) are not advertised. Ark's pay-as-you-go region still fetches its own list. Coding's `/api/coding/v3/models` returns a general Ark catalog instead of the plan's model ids, while Agent's `/api/plan/v3/models` returns 404. [`presets.go`](../../internal/provider/presets.go) defines these choices; `List`, `fetch`, `live`, `planModels`, `PlanEmbeddings`, `PlanDrawers` and `PlanVideos` in [`models.go`](../../internal/provider/models.go) apply them when adding, refreshing and reading cached models. `TestVolcengineModelLists` checks that the plans make no list requests, ignore old cached lists and return their own preset models; pay-as-you-go and an explicit list URL still make requests.
|
||||
- A gateway key held to some accounts (#905) is held to those of the providers its list names: a provider it names no account of, the key uses as it always did. The list keeps an account by its stable id — `logins.json`'s `id`, set once written and kept through renames; the agents that keep no logins (and plugins) are known by a hash of the account's name, so an account renamed there drops out of a key's list, holding it closer, never wider. Storing an id for every agent is a larger change, not this one's.
|
||||
- A sub2api key's windows are fixed: each starts at the key's first request after it was empty, aligned to the relay's day, and a window not started yet says `used 0` with no `reset_at`, so it is taken to renew a span from now. They count this key's spend only, not the relay's accounts behind it. `ForgetBalances` (a key or Balance URL changed) has every key's windows read again at its next ask, a read begun before dropped; until then the last reading stands, fresher than the card's, which routing's reads never write. A key changed is another key (`keyID`), with windows of its own.
|
||||
- Whether a Codex account spends its credits (`CodexNoCredits` in settings, opt-out, by lower-cased email) is the gateway's routing only. It never changes which account Codex is signed in to: `NextLogin` moves off an account at its routing's spent share, 100% at most, credits or not.
|
||||
|
||||
@@ -147,8 +147,11 @@ func Drawers(p provider.Provider) []catalog.Model {
|
||||
if p.Account != nil || (p.Base(provider.Chat) == "" && p.Base(provider.Responses) == "") {
|
||||
return nil
|
||||
}
|
||||
var out []catalog.Model
|
||||
have := map[string]bool{}
|
||||
out := p.PlanDrawers()
|
||||
have := make(map[string]bool, len(out))
|
||||
for _, m := range out {
|
||||
have[m.ID] = true
|
||||
}
|
||||
for _, c := range p.Catalogs() {
|
||||
for _, m := range catalog.Drawers(c) {
|
||||
if !have[m.ID] {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -261,6 +262,23 @@ func TestAspectOf(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolcengineAgentPlanDrawers(t *testing.T) {
|
||||
p, err := provider.FromPreset("volcengine")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pr := provider.Preset("volcengine")
|
||||
p.Chat, p.Responses, p.Anthropic = pr.Regions[1].Chat, pr.Regions[1].Responses, pr.Regions[1].Anthropic
|
||||
ds, want := Drawers(p), p.PlanDrawers()
|
||||
if len(ds) == 0 || !slices.EqualFunc(ds, want, func(a, b catalog.Model) bool { return a.ID == b.ID }) {
|
||||
t.Fatalf("Agent Plan drawers: %+v, want preset plan's %+v", ds, want)
|
||||
}
|
||||
p.Chat, p.Responses, p.Anthropic = pr.Regions[0].Chat, pr.Regions[0].Responses, pr.Regions[0].Anthropic
|
||||
if ds := Drawers(p); len(ds) != 0 {
|
||||
t.Fatalf("Coding Plan drawers: %+v", ds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogDrawers(t *testing.T) {
|
||||
fresh(t)
|
||||
for _, id := range catalog.Providers() {
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s *Server) retrieve(path, operation string) http.HandlerFunc {
|
||||
who := callerOf(r)
|
||||
call := Call{Time: start, From: provider.Chat, Agent: who.agent, Via: who.via, Model: asked}
|
||||
usage.Saw(agentOf(r))
|
||||
p, model, ok := provider.Resolve(asked)
|
||||
p, model, ok := resolveRetrievalModel(asked)
|
||||
if !ok {
|
||||
msg := fmt.Sprintf("magpie knows no model %q", asked)
|
||||
if off, isOff := provider.SwitchedOff(asked); isOff {
|
||||
@@ -155,6 +155,29 @@ func (s *Server) retrieve(path, operation string) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// resolveRetrievalModel also finds a preset plan's embedding model by its
|
||||
// bare id. Such models stay out of agents' chat-model lists, so the general
|
||||
// resolver does not otherwise see them there.
|
||||
func resolveRetrievalModel(id string) (provider.Provider, string, bool) {
|
||||
if p, model, ok := provider.Resolve(id); ok {
|
||||
return p, model, true
|
||||
}
|
||||
if strings.Contains(id, "/") {
|
||||
return provider.Provider{}, "", false
|
||||
}
|
||||
for _, p := range provider.All() {
|
||||
if !p.On() || p.DecideOnly() {
|
||||
continue
|
||||
}
|
||||
for _, m := range p.PlanEmbeddings() {
|
||||
if m.ID == id {
|
||||
return p, id, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return provider.Provider{}, "", false
|
||||
}
|
||||
|
||||
// retrieveFrom posts body to url as the provider signs its requests, and
|
||||
// reads the answer; a failure's code is the vendor's, with its message.
|
||||
func (s *Server) retrieveFrom(ctx context.Context, p provider.Provider, url string, body []byte) ([]byte, int, error) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -107,6 +108,59 @@ func TestEmbeddingsGoToTheModelsProvider(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolcengineEmbeddingResponses(t *testing.T) {
|
||||
type response struct {
|
||||
Object string `json:"object"`
|
||||
Model string `json:"model"`
|
||||
Data []struct {
|
||||
Object string `json:"object"`
|
||||
Index int `json:"index"`
|
||||
Embedding []float64 `json:"embedding"`
|
||||
} `json:"data"`
|
||||
Usage struct {
|
||||
Prompt int `json:"prompt_tokens"`
|
||||
Total int `json:"total_tokens"`
|
||||
} `json:"usage"`
|
||||
}
|
||||
for name, fixture := range map[string]string{"Coding Plan": volcengineCodingEmbeddingResponse, "Agent Plan": volcengineAgentEmbeddingResponse} {
|
||||
var out response
|
||||
if err := json.Unmarshal([]byte(fixture), &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out.Object != "list" || !strings.HasPrefix(out.Model, "doubao-embedding-vision") || len(out.Data) != 1 || out.Data[0].Object != "embedding" || len(out.Data[0].Embedding) != 2048 || out.Usage.Prompt != 23 || out.Usage.Total != 23 {
|
||||
t.Fatalf("%s embedding response: %+v", name, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPresetPlanEmbeddingResolvesOutsideChatModels(t *testing.T) {
|
||||
fresh(t)
|
||||
p, err := provider.FromPreset("volcengine")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pr := provider.Preset("volcengine")
|
||||
p.ID = "ark-agent"
|
||||
p.Chat, p.Responses, p.Anthropic = pr.Regions[1].Chat, pr.Regions[1].Responses, pr.Regions[1].Anthropic
|
||||
p.Key = "key"
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
embed := p.PlanEmbeddings()
|
||||
if len(embed) == 0 {
|
||||
t.Fatal("Agent Plan has no preset embedding model")
|
||||
}
|
||||
for _, m := range p.Exposed() {
|
||||
if m.ID == embed[0].ID {
|
||||
t.Fatalf("embedding model exposed for chat: %+v", m)
|
||||
}
|
||||
}
|
||||
got, model, ok := resolveRetrievalModel(embed[0].ID)
|
||||
if !ok || got.ID != p.ID || model != embed[0].ID {
|
||||
t.Fatalf("bare embedding resolved to %q/%q, %v", got.ID, model, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRerankGoesToTheModelsProvider(t *testing.T) {
|
||||
s, l := shelved(t)
|
||||
code, raw := postRetrieval(t, s, "/v1/rerank", `{"model":"lib/rerank-1","query":"magpie","documents":["a crow","a magpie"],"top_n":2,"return_documents":true}`)
|
||||
|
||||
+72
-18
@@ -35,10 +35,10 @@ import (
|
||||
// for it again. It says who is making the video, video_<provider>.<the
|
||||
// vendor's id>.<when it started>, so the gateway keeps nothing.
|
||||
//
|
||||
// Only a Grok subscription makes videos so far, at the Imagine API of the
|
||||
// backend Grok Build talks to: <cli-chat-proxy.grok.com/v1>/videos/generations
|
||||
// starts one and answers with its request_id, and /videos/{request_id} is
|
||||
// answered 202 while it is made and 200 with the video's URL when it is.
|
||||
// A Grok subscription uses the Imagine API of the backend Grok Build talks
|
||||
// to: <cli-chat-proxy.grok.com/v1>/videos/generations starts one and answers
|
||||
// with its request_id. Volcengine Agent Plan uses Ark's asynchronous content
|
||||
// generation tasks under its /api/plan/v3 base.
|
||||
//
|
||||
// Another magpie's videos (a Remote magpie's, #545) are asked of it, at its
|
||||
// own videos API: its id for one goes, encoded, in the id given here, and
|
||||
@@ -57,7 +57,8 @@ var grokVideoAspects = []string{"1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3
|
||||
const maxVideoBytes = 512 << 20
|
||||
|
||||
// Videomakers are the models a provider can make videos with: a Grok
|
||||
// subscription's, and those another magpie listed as its own.
|
||||
// subscription's, another magpie's, and a preset plan's models when magpie
|
||||
// implements that vendor's video API.
|
||||
func Videomakers(p provider.Provider) []catalog.Model {
|
||||
if p.IsRemoteMagpie() {
|
||||
out := catalog.LiveVideomakers(p.ID)
|
||||
@@ -66,6 +67,9 @@ func Videomakers(p provider.Provider) []catalog.Model {
|
||||
}
|
||||
return out
|
||||
}
|
||||
if out := p.PlanVideos(); len(out) > 0 {
|
||||
return out
|
||||
}
|
||||
if !drawsGrok(p) {
|
||||
return nil
|
||||
}
|
||||
@@ -265,6 +269,31 @@ func pixelResolution(size string) string {
|
||||
return "480p"
|
||||
}
|
||||
|
||||
// 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.
|
||||
func volcengineVideoBody(model string, f filming) []byte {
|
||||
content := []map[string]any{{"type": "text", "text": f.Prompt}}
|
||||
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"})
|
||||
}
|
||||
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"})
|
||||
}
|
||||
req := map[string]any{"model": model, "content": content}
|
||||
if f.Seconds != "" {
|
||||
req["duration"], _ = strconv.Atoi(f.Seconds)
|
||||
}
|
||||
if ar := aspectAmong(f.Size, grokVideoAspects); ar != "" {
|
||||
req["ratio"] = ar
|
||||
}
|
||||
if res := pixelResolution(f.Size); res != "" {
|
||||
req["resolution"] = res
|
||||
}
|
||||
b, _ := json.Marshal(req)
|
||||
return b
|
||||
}
|
||||
|
||||
// grokVideoBody is f as Grok's video API takes it: the duration in whole
|
||||
// seconds, an aspect ratio and a resolution rather than a size, the first
|
||||
// frame as image and the subjects to draw from as reference_images. What
|
||||
@@ -343,7 +372,11 @@ type videoState struct {
|
||||
URL string `json:"url"`
|
||||
Duration float64 `json:"duration"`
|
||||
} `json:"video"`
|
||||
Error struct {
|
||||
Content struct {
|
||||
VideoURL string `json:"video_url"`
|
||||
} `json:"content"`
|
||||
Duration float64 `json:"duration"`
|
||||
Error struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
@@ -353,9 +386,11 @@ type videoState struct {
|
||||
func videoObject(id, model string, started time.Time, st videoState, f filming) map[string]any {
|
||||
status, progress := "queued", 0
|
||||
switch st.Status {
|
||||
case "done":
|
||||
case "done", "succeeded":
|
||||
status, progress = "completed", 100
|
||||
case "failed", "expired":
|
||||
case "running":
|
||||
status, progress = "in_progress", st.Progress
|
||||
case "failed", "expired", "cancelled":
|
||||
status, progress = "failed", st.Progress
|
||||
default:
|
||||
if st.Progress > 0 {
|
||||
@@ -372,13 +407,18 @@ func videoObject(id, model string, started time.Time, st videoState, f filming)
|
||||
switch {
|
||||
case st.Video.Duration > 0:
|
||||
obj["seconds"] = strconv.FormatFloat(st.Video.Duration, 'f', -1, 64)
|
||||
case st.Duration > 0:
|
||||
obj["seconds"] = strconv.FormatFloat(st.Duration, 'f', -1, 64)
|
||||
case f.Seconds != "":
|
||||
obj["seconds"] = f.Seconds
|
||||
}
|
||||
if status == "failed" {
|
||||
code, msg := st.Error.Code, st.Error.Message
|
||||
if st.Status == "expired" {
|
||||
switch st.Status {
|
||||
case "expired":
|
||||
code, msg = "expired", "the vendor no longer keeps this video"
|
||||
case "cancelled":
|
||||
code, msg = "cancelled", "the video was cancelled"
|
||||
}
|
||||
if msg == "" {
|
||||
msg = "the video failed"
|
||||
@@ -395,7 +435,7 @@ func videoMaker(id string) (p provider.Provider, vendorID string, started time.T
|
||||
return p, "", started, fmt.Errorf("%q isn't the id of a video magpie is making", id)
|
||||
}
|
||||
found, ferr := provider.Find(pid)
|
||||
if ferr != nil || !drawsGrok(*found) && !found.IsRemoteMagpie() {
|
||||
if ferr != nil || !drawsGrok(*found) && !found.IsRemoteMagpie() && len(found.PlanVideos()) == 0 {
|
||||
return p, "", started, fmt.Errorf("no provider %q makes videos here", pid)
|
||||
}
|
||||
if signer(*found) != by {
|
||||
@@ -463,7 +503,11 @@ func remoteVideoURL(p provider.Provider, vendorID, suffix string) string {
|
||||
// videoStatus asks the vendor how a video is going.
|
||||
func (s *Server) videoStatus(ctx context.Context, p provider.Provider, vendorID string) (videoState, int, error) {
|
||||
var st videoState
|
||||
b, code, err := s.sendAs(ctx, p, http.MethodGet, strings.TrimRight(p.Base(provider.Responses), "/")+"/videos/"+url.PathEscape(vendorID), "", nil, true)
|
||||
at := strings.TrimRight(p.Base(provider.Responses), "/") + "/videos/" + url.PathEscape(vendorID)
|
||||
if p.Preset == "volcengine" {
|
||||
at = strings.TrimRight(p.Base(provider.Responses), "/") + "/contents/generations/tasks/" + url.PathEscape(vendorID)
|
||||
}
|
||||
b, code, err := s.sendAs(ctx, p, http.MethodGet, at, "", nil, true)
|
||||
if err != nil {
|
||||
return st, code, err
|
||||
}
|
||||
@@ -536,9 +580,10 @@ func (s *Server) videosCreate(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
call.Provider, call.To = p.ID, provider.Chat
|
||||
remote := p.IsRemoteMagpie()
|
||||
volcengine := p.Preset == "volcengine" && slices.ContainsFunc(p.PlanVideos(), func(m catalog.Model) bool { return m.ID == model })
|
||||
// any grok-imagine-video*, not only those listed: the vendor's newer ones work before magpie names them
|
||||
if !remote && (len(Videomakers(p)) == 0 || !strings.HasPrefix(model, "grok-imagine-video")) {
|
||||
fail(400, fmt.Sprintf("%s/%s can't make videos: magpie makes videos with a Grok subscription's grok-imagine-video", p.ID, model))
|
||||
if !remote && !volcengine && (len(Videomakers(p)) == 0 || !strings.HasPrefix(model, "grok-imagine-video")) {
|
||||
fail(400, fmt.Sprintf("%s/%s can't make videos: magpie makes videos with a Grok subscription's grok-imagine-video or Volcengine Agent Plan's Seedance models", p.ID, model))
|
||||
return
|
||||
}
|
||||
var unmask func()
|
||||
@@ -548,11 +593,17 @@ func (s *Server) videosCreate(w http.ResponseWriter, r *http.Request) {
|
||||
// it can't make
|
||||
at, field := strings.TrimRight(p.Base(provider.Responses), "/")+"/videos/generations", "request_id"
|
||||
var body []byte
|
||||
if remote {
|
||||
switch {
|
||||
case remote:
|
||||
at, field, body = strings.TrimRight(p.Base(provider.Chat), "/")+"/videos", "id", remoteVideoBody(model, f)
|
||||
} else if body, err = grokVideoBody(model, f); err != nil {
|
||||
fail(400, err.Error())
|
||||
return
|
||||
case volcengine:
|
||||
at, field, body = strings.TrimRight(p.Base(provider.Responses), "/")+"/contents/generations/tasks", "id", volcengineVideoBody(model, f)
|
||||
default:
|
||||
body, err = grokVideoBody(model, f)
|
||||
if err != nil {
|
||||
fail(400, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), drawTimeout)
|
||||
defer cancel()
|
||||
@@ -643,7 +694,7 @@ func (s *Server) videosContent(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, provider.Chat, code, err.Error())
|
||||
return
|
||||
}
|
||||
if st.Status != "done" {
|
||||
if st.Status != "done" && st.Status != "succeeded" {
|
||||
obj := videoObject(id, "", time.Time{}, st, filming{})
|
||||
msg := fmt.Sprintf("the video isn't ready: it is %v", obj["status"])
|
||||
if e, ok := obj["error"].(map[string]string); ok {
|
||||
@@ -652,6 +703,9 @@ func (s *Server) videosContent(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, provider.Chat, 409, msg)
|
||||
return
|
||||
}
|
||||
if st.Video.URL == "" {
|
||||
st.Video.URL = st.Content.VideoURL
|
||||
}
|
||||
if st.Video.URL == "" {
|
||||
writeError(w, provider.Chat, 502, p.Name+" made the video but gave no URL for it")
|
||||
return
|
||||
|
||||
@@ -8,11 +8,13 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
@@ -119,6 +121,148 @@ func errorOf(obj map[string]any) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func TestVolcengineAgentPlanVideos(t *testing.T) {
|
||||
p, err := provider.FromPreset("volcengine")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pr := provider.Preset("volcengine")
|
||||
p.Chat, p.Responses, p.Anthropic = pr.Regions[1].Chat, pr.Regions[1].Responses, pr.Regions[1].Anthropic
|
||||
ms, want := Videomakers(p), p.PlanVideos()
|
||||
if len(ms) == 0 || !slices.EqualFunc(ms, want, func(a, b catalog.Model) bool { return a.ID == b.ID }) {
|
||||
t.Fatalf("Agent Plan videos: %+v, want preset plan's %+v", ms, want)
|
||||
}
|
||||
p.Chat, p.Responses, p.Anthropic = pr.Regions[0].Chat, pr.Regions[0].Responses, pr.Regions[0].Anthropic
|
||||
if ms := Videomakers(p); len(ms) != 0 {
|
||||
t.Fatalf("Coding Plan videos: %+v", ms)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolcengineVideoBody(t *testing.T) {
|
||||
f := filming{Prompt: "a magpie", Seconds: "6", Size: "1280x720", Start: &picture{Mime: "image/png", Data: []byte("png")}, References: []picture{{URL: "https://example.test/ref.png"}}}
|
||||
var got map[string]any
|
||||
if err := json.Unmarshal(volcengineVideoBody("doubao-seedance-2.5", f), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got["model"] != "doubao-seedance-2.5" || got["duration"] != float64(6) || got["resolution"] != "720p" || got["ratio"] != "16:9" {
|
||||
t.Fatalf("body: %+v", got)
|
||||
}
|
||||
content, _ := got["content"].([]any)
|
||||
if len(content) != 3 {
|
||||
t.Fatalf("content: %+v", got["content"])
|
||||
}
|
||||
first, _ := content[1].(map[string]any)
|
||||
reference, _ := content[2].(map[string]any)
|
||||
if first["role"] != "first_frame" || reference["role"] != "reference_image" {
|
||||
t.Fatalf("image roles: %+v", content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolcengineVideoIsStartedPolledAndFetched(t *testing.T) {
|
||||
fresh(t)
|
||||
var mu sync.Mutex
|
||||
var paths, bodies []string
|
||||
asked := map[string]int{}
|
||||
var up *httptest.Server
|
||||
up = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
paths = append(paths, r.Method+" "+r.URL.Path)
|
||||
bodies = append(bodies, string(body))
|
||||
if r.URL.Path != "/ark/video.mp4" && r.Header.Get("Authorization") != "Bearer key" {
|
||||
w.WriteHeader(401)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch {
|
||||
case r.Method == http.MethodPost && r.URL.Path == "/api/plan/v3/contents/generations/tasks" && strings.Contains(string(body), "FAILING"):
|
||||
io.WriteString(w, volcengineVideoFailedCreateResponse)
|
||||
case r.Method == http.MethodPost && r.URL.Path == "/api/plan/v3/contents/generations/tasks":
|
||||
io.WriteString(w, volcengineVideoCreateResponse)
|
||||
case r.Method == http.MethodGet && r.URL.Path == "/api/plan/v3/contents/generations/tasks/cgt-20261008165954-4sc9n":
|
||||
asked["success"]++
|
||||
if asked["success"] == 1 {
|
||||
io.WriteString(w, volcengineVideoRunningResponse)
|
||||
} else {
|
||||
io.WriteString(w, strings.Replace(volcengineVideoSucceededResponse, "VIDEO_URL", up.URL+"/ark/video.mp4", 1))
|
||||
}
|
||||
case r.Method == http.MethodGet && r.URL.Path == "/api/plan/v3/contents/generations/tasks/cgt-20261008165955-bgckq":
|
||||
io.WriteString(w, volcengineVideoFailedResponse)
|
||||
case r.Method == http.MethodGet && r.URL.Path == "/ark/video.mp4":
|
||||
w.Header().Set("Content-Type", "video/mp4")
|
||||
io.WriteString(w, "ark-video-bytes")
|
||||
default:
|
||||
w.WriteHeader(404)
|
||||
io.WriteString(w, `{"error":{"code":"not_found","message":"unexpected path"}}`)
|
||||
}
|
||||
}))
|
||||
t.Cleanup(up.Close)
|
||||
|
||||
p, err := provider.FromPreset("volcengine")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.ID, p.Key = "ark-agent", "key"
|
||||
p.Chat, p.Responses = up.URL+"/api/plan/v3", up.URL+"/api/plan/v3"
|
||||
p.Anthropic = up.URL + "/api/plan"
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s := New()
|
||||
code, obj, raw, _ := request(t, s, http.MethodPost, "/v1/videos", "application/json", `{"model":"ark-agent/doubao-seedance-2.0-mini","prompt":"a magpie","seconds":5,"size":"854x480"}`)
|
||||
if code != 200 || obj["status"] != "queued" || obj["model"] != "ark-agent/doubao-seedance-2.0-mini" {
|
||||
t.Fatalf("create: %d %s", code, raw)
|
||||
}
|
||||
id, _ := obj["id"].(string)
|
||||
code, obj, raw, _ = request(t, s, http.MethodGet, "/v1/videos/"+id, "", "")
|
||||
if code != 200 || obj["status"] != "in_progress" {
|
||||
t.Fatalf("running: %d %s", code, raw)
|
||||
}
|
||||
code, obj, raw, _ = request(t, s, http.MethodGet, "/v1/videos/"+id, "", "")
|
||||
if code != 200 || obj["status"] != "completed" || obj["seconds"] != "5" {
|
||||
t.Fatalf("succeeded: %d %s", code, raw)
|
||||
}
|
||||
code, _, raw, head := request(t, s, http.MethodGet, "/v1/videos/"+id+"/content", "", "")
|
||||
if code != 200 || string(raw) != "ark-video-bytes" || head.Get("Content-Type") != "video/mp4" {
|
||||
t.Fatalf("content: %d %q %v", code, raw, head)
|
||||
}
|
||||
|
||||
code, failed, raw, _ := request(t, s, http.MethodPost, "/v1/videos", "application/json", `{"model":"ark-agent/doubao-seedance-2.0-mini","prompt":"FAILING"}`)
|
||||
if code != 200 {
|
||||
t.Fatalf("create failing: %d %s", code, raw)
|
||||
}
|
||||
code, failed, raw, _ = request(t, s, http.MethodGet, "/v1/videos/"+failed["id"].(string), "", "")
|
||||
errObj, _ := failed["error"].(map[string]any)
|
||||
if code != 200 || failed["status"] != "failed" || errObj["code"] != "OutputVideoSensitiveContentDetected.PolicyViolation" || !strings.Contains(errObj["message"].(string), "copyright restrictions") {
|
||||
t.Fatalf("failed: %d %s", code, raw)
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(paths) < 7 || paths[0] != "POST /api/plan/v3/contents/generations/tasks" || !strings.Contains(bodies[0], `"content":[`) || !strings.Contains(bodies[0], `"duration":5`) || !slices.Contains(paths, "GET /ark/video.mp4") {
|
||||
t.Fatalf("upstream paths %v, create body %s", paths, bodies[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolcengineVideoState(t *testing.T) {
|
||||
var st videoState
|
||||
if err := json.Unmarshal([]byte(`{"status":"succeeded","model":"doubao-seedance-2.5","content":{"video_url":"https://example.test/video.mp4"},"duration":5}`), &st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obj := videoObject("video_volcengine.task.1.0", "volcengine/"+st.Model, time.Unix(1, 0), st, filming{})
|
||||
if obj["status"] != "completed" || obj["progress"] != 100 || obj["seconds"] != "5" || st.Content.VideoURL != "https://example.test/video.mp4" {
|
||||
t.Fatalf("completed state: %+v, object: %+v", st, obj)
|
||||
}
|
||||
for status, want := range map[string]string{"queued": "queued", "running": "in_progress", "cancelled": "failed"} {
|
||||
st = videoState{Status: status}
|
||||
if got := videoObject("id", "model", time.Unix(1, 0), st, filming{})["status"]; got != want {
|
||||
t.Errorf("%s became %v, want %s", status, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVideomakersAreAGrokSubscriptions(t *testing.T) {
|
||||
grokSignedIn(t)
|
||||
newGrokMedia(t)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -518,14 +518,14 @@ func basePath(raw string) string {
|
||||
// or gives the plan's when the list has none; a plan with models but no
|
||||
// Only gives them only when there is no list. Any other provider's list is
|
||||
// as it came. A region with models of its own (Tencent Cloud's Token Plan,
|
||||
// beside TokenHub's pay as you go) is a plan with those.
|
||||
// or one of Volcengine's plans) is a plan with those.
|
||||
func (p Provider) planModels(ms []catalog.Model) []catalog.Model {
|
||||
pr := Preset(p.Preset)
|
||||
if pr == nil {
|
||||
return ms
|
||||
}
|
||||
models := pr.Models
|
||||
if r := p.regionOf(pr); r != nil && len(r.Models) > 0 {
|
||||
if r := p.regionOf(pr); r != nil && r.Models != nil {
|
||||
models = r.Models
|
||||
}
|
||||
if pr.Only == "" && (len(models) == 0 || len(ms) > 0) {
|
||||
@@ -571,6 +571,42 @@ func (p Provider) planModels(ms []catalog.Model) []catalog.Model {
|
||||
return out
|
||||
}
|
||||
|
||||
// PlanEmbeddings are the embedding models explicitly included in the preset
|
||||
// region's plan. They are resolved by the embeddings API but kept out of
|
||||
// agents' chat-model lists.
|
||||
func (p Provider) PlanEmbeddings() []catalog.Model {
|
||||
return p.planMedia(func(r *Region) []string { return r.Embeddings }, false, false)
|
||||
}
|
||||
|
||||
// PlanDrawers are the image-generation models explicitly included in the
|
||||
// preset region's plan. They are separate from its chat models.
|
||||
func (p Provider) PlanDrawers() []catalog.Model {
|
||||
return p.planMedia(func(r *Region) []string { return r.Drawers }, true, false)
|
||||
}
|
||||
|
||||
// PlanVideos are the video-generation models explicitly included in the
|
||||
// preset region's plan.
|
||||
func (p Provider) PlanVideos() []catalog.Model {
|
||||
return p.planMedia(func(r *Region) []string { return r.Videos }, false, true)
|
||||
}
|
||||
|
||||
func (p Provider) planMedia(ids func(*Region) []string, draws, films bool) []catalog.Model {
|
||||
pr := Preset(p.Preset)
|
||||
if pr == nil {
|
||||
return nil
|
||||
}
|
||||
r := p.regionOf(pr)
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
models := ids(r)
|
||||
out := make([]catalog.Model, 0, len(models))
|
||||
for _, id := range models {
|
||||
out = append(out, catalog.Model{ID: id, Name: id, Provider: p.ID, Draws: draws, Films: films})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// fixV1 adds the /v1 an OpenAI-style base URL was given without, when
|
||||
// the models were found only under it: base/models didn't answer and
|
||||
// base/v1/models did. The list is asked for at both, but a request goes
|
||||
|
||||
@@ -82,9 +82,14 @@ type Region struct {
|
||||
// than the preset's (Tencent Cloud's pay as you go, beside its plan's
|
||||
// none), is that entry's id.
|
||||
Catalog string `json:"catalog,omitempty"`
|
||||
// Models are a plan's, for a region that is one beside pay as you go
|
||||
// (PresetDef.Models, for the region alone).
|
||||
Models []string `json:"models,omitempty"`
|
||||
// Models are a plan's text models, for a region that is one beside
|
||||
// another plan or pay as you go (PresetDef.Models, for the region alone).
|
||||
// Embeddings, Drawers and Videos are its non-chat models, kept apart from
|
||||
// agents' model pickers.
|
||||
Models []string `json:"models,omitempty"`
|
||||
Embeddings []string `json:"embeddings,omitempty"`
|
||||
Drawers []string `json:"drawers,omitempty"`
|
||||
Videos []string `json:"videos,omitempty"`
|
||||
// Decide is the region's decision API, for a preset that routes groups
|
||||
Decide string `json:"decide,omitempty"`
|
||||
}
|
||||
@@ -266,16 +271,21 @@ var presets = []PresetDef{
|
||||
Note: "火山方舟 · Coding / Agent Plan",
|
||||
Website: "https://www.volcengine.com/docs/82379/1925114", KeysURL: "https://ark.volcengine.com/region:cn-beijing/apikey",
|
||||
RegionLabel: "Plan", Regions: []Region{
|
||||
{ID: "coding", Name: "Coding Plan", Chat: "https://ark.cn-beijing.volces.com/api/coding/v3", Responses: "https://ark.cn-beijing.volces.com/api/coding/v3", Anthropic: "https://ark.cn-beijing.volces.com/api/coding"},
|
||||
{ID: "agent", Name: "Agent Plan", Chat: "https://ark.cn-beijing.volces.com/api/plan/v3", Responses: "https://ark.cn-beijing.volces.com/api/plan/v3", Anthropic: "https://ark.cn-beijing.volces.com/api/plan"},
|
||||
{ID: "coding", Name: "Coding Plan", Chat: "https://ark.cn-beijing.volces.com/api/coding/v3", Responses: "https://ark.cn-beijing.volces.com/api/coding/v3", Anthropic: "https://ark.cn-beijing.volces.com/api/coding",
|
||||
Models: []string{"ark-code-latest", "doubao-seed-evolving", "doubao-seed-2.1-pro", "doubao-seed-2.1-lite", "doubao-seed-2.1-turbo",
|
||||
"doubao-seed-2.0-mini", "minimax-m3", "glm-5.3", "glm-5.3-flash", "deepseek-v4.1-flash", "deepseek-v4-flash", "deepseek-v4-pro",
|
||||
"kimi-k2.7-code", "kimi-k2.8-preview", "kimi-k3"},
|
||||
Embeddings: []string{"doubao-embedding-vision"}},
|
||||
{ID: "agent", Name: "Agent Plan", Chat: "https://ark.cn-beijing.volces.com/api/plan/v3", Responses: "https://ark.cn-beijing.volces.com/api/plan/v3", Anthropic: "https://ark.cn-beijing.volces.com/api/plan",
|
||||
Models: []string{"ark-code-latest", "doubao-seed-evolving", "doubao-seed-2.1-pro", "doubao-seed-2.1-lite", "doubao-seed-2.1-turbo",
|
||||
"doubao-seed-2.0-mini", "minimax-m3", "glm-5.3", "glm-5.3-flash", "deepseek-v4.1-flash", "deepseek-v4-flash", "deepseek-v4-pro",
|
||||
"kimi-k2.7-code", "kimi-k2.8-preview", "kimi-k3"},
|
||||
Embeddings: []string{"doubao-embedding-vision"},
|
||||
Drawers: []string{"doubao-seedream-5-0-pro"},
|
||||
Videos: []string{"doubao-seedance-2.0", "doubao-seedance-2.0-fast", "doubao-seedance-2.0-mini", "doubao-seedance-2.5"}},
|
||||
{ID: "api", Name: "Pay as you go", Chat: "https://ark.cn-beijing.volces.com/api/v3", Responses: "https://ark.cn-beijing.volces.com/api/v3", Lists: true},
|
||||
},
|
||||
NoList: true,
|
||||
// the plans' model names, lowercase as their quick-start pages list
|
||||
// them; ark-code-latest is whichever the console has picked
|
||||
Models: []string{"ark-code-latest", "doubao-seed-evolving", "doubao-seed-2.1-pro", "doubao-seed-2.1-lite", "doubao-seed-2.0-mini",
|
||||
"minimax-m3", "glm-5.3", "glm-5.3-flash", "deepseek-v4.1-flash", "deepseek-v4-flash", "deepseek-v4-pro",
|
||||
"kimi-k2.7-code", "kimi-k2.8-preview", "kimi-k3"}},
|
||||
NoList: true},
|
||||
{ID: "qwen", Name: "Qwen", Icon: "qwen-color", Kind: KindVendor, Catalog: "alibaba",
|
||||
Chat: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", Anthropic: "https://dashscope-intl.aliyuncs.com/apps/anthropic",
|
||||
Note: "DashScope · intl",
|
||||
|
||||
@@ -28,13 +28,50 @@ func TestVolcengineArkPlans(t *testing.T) {
|
||||
pr.Regions[2].Chat != "https://ark.cn-beijing.volces.com/api/v3" || pr.Regions[2].Anthropic != "" {
|
||||
t.Fatalf("plans: %+v", pr.Regions)
|
||||
}
|
||||
for _, id := range pr.Models {
|
||||
if id != strings.ToLower(id) {
|
||||
t.Fatalf("model ids are lowercase, as the quick-start page has them: %q", id)
|
||||
coding, agent, payg := pr.Regions[0], pr.Regions[1], pr.Regions[2]
|
||||
if pr.Models != nil || coding.Models == nil || agent.Models == nil || payg.Models != nil {
|
||||
t.Fatalf("model sources aren't defined per plan: coding %v, agent %v, pay as you go %v", coding.Models, agent.Models, payg.Models)
|
||||
}
|
||||
if len(coding.Embeddings) == 0 || len(agent.Embeddings) == 0 || len(payg.Embeddings) != 0 {
|
||||
t.Fatalf("embedding models by plan: coding %v, agent %v, pay as you go %v", coding.Embeddings, agent.Embeddings, payg.Embeddings)
|
||||
}
|
||||
if len(coding.Drawers) != 0 || len(coding.Videos) != 0 || len(agent.Drawers) == 0 || len(agent.Videos) == 0 || len(payg.Drawers) != 0 || len(payg.Videos) != 0 {
|
||||
t.Fatalf("media models aren't confined to Agent Plan: coding %+v, agent %+v, pay as you go %+v", coding, agent, payg)
|
||||
}
|
||||
for _, models := range [][]string{coding.Models, coding.Embeddings, agent.Models, agent.Embeddings, agent.Drawers, agent.Videos} {
|
||||
for _, id := range models {
|
||||
if id != strings.ToLower(id) {
|
||||
t.Fatalf("model ids are lowercase, as the quick-start page has them: %q", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
if got := p.planModels(nil); len(got) != len(pr.Models) || got[0].ID != "ark-code-latest" {
|
||||
t.Fatalf("plan's: %+v", got)
|
||||
if got := modelIDs(p.planModels(nil)); !slices.Equal(got, coding.Models) {
|
||||
t.Fatalf("Coding Plan models: %v, want preset region's %v", got, coding.Models)
|
||||
}
|
||||
if got := modelIDs(p.PlanEmbeddings()); !slices.Equal(got, coding.Embeddings) {
|
||||
t.Fatalf("Coding Plan embeddings: %v, want preset region's %v", got, coding.Embeddings)
|
||||
}
|
||||
for _, id := range coding.Embeddings {
|
||||
if slices.Contains(modelIDs(p.Available()), id) || slices.Contains(modelIDs(p.Exposed()), id) {
|
||||
t.Fatalf("embedding model %q exposed as a chat model", id)
|
||||
}
|
||||
}
|
||||
p.atRegionOf(pr, agent)
|
||||
if got := modelIDs(p.planModels(nil)); !slices.Equal(got, agent.Models) {
|
||||
t.Fatalf("Agent Plan models: %v, want preset region's %v", got, agent.Models)
|
||||
}
|
||||
if got := modelIDs(p.PlanEmbeddings()); !slices.Equal(got, agent.Embeddings) {
|
||||
t.Fatalf("Agent Plan embeddings: %v, want preset region's %v", got, agent.Embeddings)
|
||||
}
|
||||
if got := modelIDs(p.PlanDrawers()); !slices.Equal(got, agent.Drawers) {
|
||||
t.Fatalf("Agent Plan drawers: %v, want preset region's %v", got, agent.Drawers)
|
||||
}
|
||||
if got := modelIDs(p.PlanVideos()); !slices.Equal(got, agent.Videos) {
|
||||
t.Fatalf("Agent Plan videos: %v, want preset region's %v", got, agent.Videos)
|
||||
}
|
||||
p.atRegionOf(pr, pr.Regions[2])
|
||||
if got := p.planModels(nil); len(got) != 0 {
|
||||
t.Fatalf("pay as you go preset models: %+v", got)
|
||||
}
|
||||
// an entry imported from another app at an Ark endpoint is known as Ark
|
||||
im, _ := imported("Ark", "k", endpoints{chat: "https://ark.cn-beijing.volces.com/api/plan/v3"}, nil)
|
||||
@@ -84,7 +121,7 @@ func TestVolcengineModelLists(t *testing.T) {
|
||||
if err := catalog.SaveLive(p.ID, p.Chat, listed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := pr.Models
|
||||
want := r.Models
|
||||
if r.ID == "api" {
|
||||
want = []string{"doubao-seed-2-0-pro-260215"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user