jiangguochao666 asked for each provider's free models to show in Routing and the model settings, to route to them. The green free tag was shown only for a plan's free model or a model with "free" in its name. provider.PricedFree says a model is free only when its price for that provider is known to be $0: - A price the user set comes first (provider/model, provider/*, then the model's own key). A $0 one makes it free, and any other price, a paid tier included, makes it paid. - Otherwise the provider's own catalogs decide. A $0 from a plan's catalog (-plan, membership catalogs) is the plan's per-token price, not free. A $0 from only the model's maker is not free either: a relay serving Zhipu's free glm-4.7-flash may charge for it. - No known price means not free. FreeModel (Free first, Cheapest first routing) is unchanged. From the local models.dev cache this tags: - every model of NVIDIA NIM and ModelScope; - the :free / -free models of OpenRouter, OpenCode Zen and Go, Kilo, AIHubMix, ZenMux, Vercel, Requesty and other relays; - Zhipu's and Z.ai's glm-4.x-flash. No coding or token plan is tagged. Where it shows, with the hover "free: listed at $0 on this provider": - an agent's model picker (agent.Option.Zero); - the provider editor's model chips, and its Free only button (modelJSON.Zero); - Routing's Add a model and classifier pickers (modelRef.Zero). The word is new in en, zh, zh-TW, ja and de. Tests, each red on the old code: - TestPricedFreeIsTheProvidersOwnZero: own, plan, maker-only, unpriced and user prices. - TestPickerSaysAZeroPricedModelIsFree: Option.Zero, cleared at once by a price the user saves. - TestZeroPricedModelsSayFree: the editor's and Routing's JSON. - zero-priced-free.test.cjs: the three surfaces, in Chromium and WebKit, at 1100 and 420px, in all 5 languages. It checks the tag's text, hover and fit, that the paid model has no tag, that a plan's free model keeps its own hover, no sideways scroll and no page errors. Broken by hand (each restored, diff checked): - The source check ignored (maker and plan $0 count): the provider test goes red on the plan model and the relay's glm-4.7-flash. - PricedFree always false: the provider, agent and gui tests go red. - The user's price ignored: the provider and agent tests go red. - The badge's o.zero / m.zero and Routing's zero dropped in app.js and routing/client.js: zero-priced-free goes red, "the $0 model has no free tag in the agent's picker". Run at this commit's tree (base3f1f1882a): - mote, go test -timeout 45m ./...: 84 ok, 19 with no tests, 3 FAIL. Each red is filed and fails the same way at origin/main7d022bdb6: - TestEveryRouteHasACommandOrIsNamed: /api/context/reply, #5026. - TestMainWindowCorners/macOS_26_SDK: macOS 27, #3949. - TestCompactionOverByteCapEveryTime: red only in the full gateway run, ok alone here and at main, #4862. TestCoreScriptBudget passed; no budget was raised. - gofmt -l: clean. GOOS=windows go vet (mote): ok. go vet -tags gtk3 on Linux (wsl, magpie-desktop): ok. A cross GOOS=linux vet from macOS fails inside wails' cgo files on main too. - wsl: zero-priced-free + i18n-keys, 24 of 24 pass. - wsl: the whole GUI suite, concurrency 4: 19062 of 19585 pass, 523 fail in 127 files, at load ~86 on a shared box. Those 127 files run again at concurrency 2: 465 red here and 417 at the base3f1f1882a, the same files on both. 11 files with a red only on this tree, the routing, model and search ones near this change, run again alone at load ~3: the same 7 fail on both trees (33 here, 27 at the base), and which cases fail changes from run to run with the same errors. None is in a test that reads the free tag. Filed already: #3096 and #5035/#5088 (routing-rule-*, rest-try-now), #4388 (model-chip-steady alone on WSL), #4585 and #4932 (under load). The other files red only on this tree (usage wheels, tray, archive rows) were not run again alone; nothing in them reads the free tag. Not tried: a real provider's list in the live app (the tests use fixture catalogs); Free first routing choosing a $0-priced model it didn't choose before (FreeModel is unchanged on purpose).
59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// jiangguochao666 on X: the provider editor's model list and the Routing
|
|
// page's add-a-model picker say free by a model its provider lists at $0
|
|
// (zero, provider.PricedFree), as OpenRouter's foo:free, and not by the
|
|
// paid foo beside it; a paid model sends no zero at all.
|
|
func TestZeroPricedModelsSayFree(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{"zfree":{"models":{
|
|
"foo:free":{"id":"foo:free","cost":{"input":0,"output":0}},
|
|
"foo":{"id":"foo","cost":{"input":1,"output":2}}}}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
p := provider.Provider{ID: "zf", Name: "ZF", Catalog: "zfree", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"foo:free", "foo"}}
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ms := []catalog.Model{{ID: "foo:free"}, {ID: "foo"}}
|
|
zero := map[string]bool{}
|
|
for _, m := range providerInfoWith(p, provider.Listing{Available: ms, Exposed: ms}, nil, nil).Models {
|
|
zero[m.ID] = m.Zero
|
|
b, _ := json.Marshal(m)
|
|
if !m.Zero && strings.Contains(string(b), `"zero"`) {
|
|
t.Errorf("a paid model sends zero: %s", b)
|
|
}
|
|
}
|
|
if !zero["foo:free"] || zero["foo"] {
|
|
t.Fatalf("the editor's zero: %v, want foo:free only", zero)
|
|
}
|
|
|
|
zero = map[string]bool{}
|
|
for _, m := range groupsState().Models {
|
|
zero[m.ID] = m.Zero
|
|
}
|
|
if !zero["zf/foo:free"] || zero["zf/foo"] {
|
|
t.Fatalf("the Routing page's zero: %v, want zf/foo:free only", zero)
|
|
}
|
|
}
|