axelburks on Discord: "供应商里方舟的配置页,有图像模型选项能勾选模型,但是没 有视频模型选项不能勾选视频模型". A Volcengine Ark key's editor listed its Seedream models under Image models, to tick, and had its Seedance models among the chat models or nowhere. Cause, two parts: - The editor had no video section at all: video models had no list and no hidden set (gateway-routing.md said "Video models aren't listed in the editor, so there is nothing to hide there"). - catalog's live parse read only "kind" and modalities.input/output. Ark's /api/v3/models marks no kind: it says domain "VideoGeneration" / "ImageGeneration" and modalities.input_modalities/output_modalities. So Seedance came back as a chat model, and 3D models (output 3d, no text) as chat models too. Change: - catalog: a live row with no kind is a video model when its domain is VideoGeneration or it outputs video without text, an image model for ImageGeneration or image without text; Ark's input_modalities / output_modalities are read when input/output aren't there, so a model that gives no text (Ark's 3D) is left out of the chat list. TestFetchArkMarksVideoModels runs on a captured Ark list (testdata/volcengine-ark-models-2026-11-03.json, fetched read-only with GET /api/v3/models, no key in it). - provider: HiddenVideomakers beside HiddenDrawers, VideomakerHidden. - gateway: VideomakersOf (Videomakers on a given list, for the editor), OfferedVideomakers = Videomakers less the unticked ones, read by AutoVideomaker, videomakerObjects (another magpie's list) and mediaModels(true) (generate_video). A hidden one still makes its video when named: bareVideomaker, videosCreate and arkFilms read Videomakers. - gui: the editor's Video models section (renderVideomakers), filmIds and hiddenVideomakers on /api/providers, kept on save as hiddenDrawers is; i18n for every language. app.js comments cut to stay under TestCoreScriptBudget, which this change reached; no raise. - docs: gateway-routing.md's Hidden image models section. Old data: an Ark list fetched before keeps Seedance among its chat models until its list is fetched again; customVideomakers already counts any Seedance id an Ark key lists or picks as a video model, so it makes videos and shows under Video models now. Run on mote, this change and the next (/v1/models ?kind=, gateway and docs only) rebased on f4c664a09; this commit's own tree, on17f2387e1, gave the same Go results with Linux and Windows vet of ./internal/... clean: - go test -count=1 -timeout 45m ./internal/catalog ./internal/provider ./internal/gateway ./internal/gui: catalog, provider and gateway ok; gui red only in TestMainWindowCorners/macOS_26_SDK (#3949, red on main). - GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. gofmt -l: nothing. - GUI (at the next commit's tree, which adds no GUI file or script): the 51 provider-*, drawers, image-models, i18n and video-models-hide files, both engines, every language, wide and narrow: 1161 of 1188 ok. The 27 reds are 5 files that are red the same 27 at origin/maind1cdce130run alone: provider-fetch-again (#3292/#5057), provider-models-rest (#4396), provider-picks-stay (#4397), provider-levels-scroll (#4395), provider-typed (#4673). video-models-hide: 22 of 22 ok. - The whole GUI suite (all files) ran earlier at this change on8af751987, 347 of 19153 red at load 100 to 200; the 66 files with a red, run again alone, are red in the same tests at origin/main17f2387e1(all filed: #4388, #4391, #4398, #4320, #4541/#5013, #2564, #4244, #4304 and the above). Rebased again ontod1cdce130(sessions, Cursor mover, library and routing plugins, group-unlists; nothing this change touches but gateway.go, which merged clean) and run there: TestCoreScriptBudget and internal/gui's new tests, the gateway's ?kind= and video tests, internal/provider and internal/catalog, video-models-hide 22 of 22: ok. Broken by hand, each red, then put back: - the domain/output check in catalog's live parse: TestFetchArkMarksVideoModels red - OfferedVideomakers returning Videomakers whole: TestHiddenVideomakerLeavesListsButStillFilms red - the editor's filmIds left empty: TestVideoModelsHidden red - a save without hiddenVideomakers dropping the old ones: TestVideoModelsHidden red - renderVideomakers' call in the editor left out: video-models-hide 22 of 22 red - a chip's click not changing the draft: video-models-hide 22 of 22 red Not tried: no real Ark video was made (no money spent); the list parse was checked on a real Ark list fetched read-only. The editor was not opened in the real app, only in the GUI tests' fake API. Credit: axelburks on Discord.
143 lines
4.5 KiB
Go
143 lines
4.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// What a model makes, as the user says it (shen-joe, #1399): a provider set
|
|
// up with a base URL tells magpie its image and video models by its own
|
|
// model list ("kind": "image" or "video") or, for images, by a model's name.
|
|
// A relay whose list says neither — most don't — leaves a video model
|
|
// making nothing, and an image model with an odd name drawing nothing. The
|
|
// user can say so of one model instead, kept in settings' ModelKinds by
|
|
// "<provider id>/<model id>" as a model's name is: an image model is drawn
|
|
// with at the images API under the provider's base, a video model asked at
|
|
// its videos API, as one its list marks is (gateway's Drawers and
|
|
// customVideomakers).
|
|
const (
|
|
KindImage = "image"
|
|
KindVideo = "video"
|
|
)
|
|
|
|
// MarksKinds is whether p's models can be said to make images or videos: a
|
|
// provider set up with a base URL, which magpie asks at the OpenAI-shaped
|
|
// images and videos APIs under it. A subscription's account, another magpie
|
|
// (whose own list says) and a decision API's can't.
|
|
func (p Provider) MarksKinds() bool {
|
|
return p.Account == nil && !p.IsRemoteMagpie() && !p.DecideOnly() &&
|
|
(p.Base(Chat) != "" || p.Base(Responses) != "")
|
|
}
|
|
|
|
// ModelKind is what the user said p's model makes: KindImage, KindVideo,
|
|
// or "" when they said nothing, or p can't be told (MarksKinds).
|
|
func (p Provider) ModelKind(model string) string {
|
|
if !p.MarksKinds() {
|
|
return ""
|
|
}
|
|
return modelKindIn(heldSettings(), p.ID, model)
|
|
}
|
|
|
|
func modelKindIn(s settings.Settings, pid, model string) string {
|
|
switch k := s.ModelKinds[pid+"/"+model]; k {
|
|
case KindImage, KindVideo:
|
|
return k
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// KindModels are the ids of p's models the user said make kind, those it
|
|
// still serves, sorted (a provider's id has no "/", so a model's may:
|
|
// OpenRouter's).
|
|
func (p Provider) KindModels(kind string) []string {
|
|
if !p.MarksKinds() {
|
|
return nil
|
|
}
|
|
var out []string
|
|
prefix := p.ID + "/"
|
|
for key, k := range heldSettings().ModelKinds {
|
|
if model, ok := strings.CutPrefix(key, prefix); ok && k == kind && model != "" {
|
|
out = append(out, model)
|
|
}
|
|
}
|
|
if len(out) == 0 {
|
|
return nil
|
|
}
|
|
slices.Sort(out)
|
|
return slices.DeleteFunc(out, func(m string) bool { return !p.hasKindable(m) })
|
|
}
|
|
|
|
// hasKindable is whether p has model: one it serves to chat with, or one
|
|
// its fetched list has that it leaves out of those, as making images or
|
|
// videos.
|
|
func (p Provider) hasKindable(model string) bool {
|
|
if p.serves(model) {
|
|
return true
|
|
}
|
|
all, _ := catalog.LiveAll(p.ID)
|
|
return slices.ContainsFunc(all, func(m catalog.Model) bool { return m.ID == model })
|
|
}
|
|
|
|
// SetModelKind says what a provider's model, spelt "provider/model", makes:
|
|
// KindImage, KindVideo, or "" to leave it to its vendor's list and name.
|
|
func SetModelKind(ref, kind string) error {
|
|
_, err := setModelKind(ref, kind)
|
|
return err
|
|
}
|
|
|
|
func setModelKind(ref, kind string) (bool, error) {
|
|
p, model, err := splitRef(ref)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
kind = strings.TrimSpace(kind)
|
|
if kind != "" && kind != KindImage && kind != KindVideo {
|
|
return false, fmt.Errorf("a model makes %q or %q, not %q", KindImage, KindVideo, kind)
|
|
}
|
|
if kind != "" {
|
|
if !p.MarksKinds() {
|
|
return false, errors.New(p.ID + " makes images and videos only as its own API does: none of its models can be said to make them")
|
|
}
|
|
if !p.hasKindable(model) {
|
|
return false, fmt.Errorf("%s has no model %s (magpie provider %s lists them)", p.ID, model, p.ID)
|
|
}
|
|
}
|
|
s := settings.Load()
|
|
key := p.ID + "/" + model
|
|
if s.ModelKinds[key] == kind {
|
|
return false, nil
|
|
}
|
|
if kind == "" {
|
|
delete(s.ModelKinds, key)
|
|
} else {
|
|
if s.ModelKinds == nil {
|
|
s.ModelKinds = map[string]string{}
|
|
}
|
|
s.ModelKinds[key] = kind
|
|
}
|
|
if err := settings.Save(s); err != nil {
|
|
return false, err
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
// DrawerHidden is whether the user unticked p's image model in its editor
|
|
// (HiddenDrawers): it is left out of the lists an image model is picked
|
|
// from and of Automatic's choice, and still draws when named.
|
|
func (p Provider) DrawerHidden(model string) bool {
|
|
return slices.Contains(p.HiddenDrawers, model)
|
|
}
|
|
|
|
// VideomakerHidden is whether the user unticked p's video model in its
|
|
// editor (HiddenVideomakers): it is left out of the lists a video model is
|
|
// picked from and of Automatic's choice, and still makes videos when
|
|
// named.
|
|
func (p Provider) VideomakerHidden(model string) bool {
|
|
return slices.Contains(p.HiddenVideomakers, model)
|
|
}
|