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).
89 lines
3.4 KiB
Go
89 lines
3.4 KiB
Go
package provider
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// jiangguochao666 on X asked the pickers to say which of each provider's
|
|
// models are free. PricedFree says so only where the provider's own price
|
|
// is $0: OpenRouter's foo:free, not foo, and not the same id another
|
|
// provider charges for. A model nothing prices is not free, nor one a
|
|
// plan's catalog lists at $0 (that is the plan's per-token price), nor one
|
|
// only its maker gives away (a relay serving Zhipu's free glm-4.7-flash
|
|
// may charge for it). A price the user set is theirs: one that isn't 0, at
|
|
// any size, makes the model paid, and a $0 one makes it free.
|
|
func TestPricedFreeIsTheProvidersOwnZero(t *testing.T) {
|
|
prefsHome(t)
|
|
data := `{
|
|
"zfree":{"models":{
|
|
"foo:free":{"id":"foo:free","cost":{"input":0,"output":0}},
|
|
"foo":{"id":"foo","cost":{"input":1,"output":2}},
|
|
"shared":{"id":"shared","cost":{"input":0,"output":0,"cache_read":0}},
|
|
"cached":{"id":"cached","cost":{"input":0,"output":0,"cache_read":0.1}},
|
|
"nocost":{"id":"nocost"}
|
|
}},
|
|
"zpaid":{"models":{"shared":{"id":"shared","cost":{"input":3,"output":15}}}},
|
|
"zz-coding-plan":{"models":{"plan-model":{"id":"plan-model","cost":{"input":0,"output":0}}}},
|
|
"zhipuai":{"models":{"glm-4.7-flash":{"id":"glm-4.7-flash","cost":{"input":0,"output":0}}}}
|
|
}`
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(data), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
|
|
free := Provider{ID: "zf", Name: "ZF", Catalog: "zfree", Key: "k", Chat: "http://127.0.0.1:9/v1"}
|
|
paid := Provider{ID: "zp", Name: "ZP", Catalog: "zpaid", Key: "k", Chat: "http://127.0.0.1:9/v1"}
|
|
plan := Provider{ID: "zc", Name: "ZC", Catalog: "zz-coding-plan", Key: "k", Chat: "http://127.0.0.1:9/v1"}
|
|
zhipu := Provider{ID: "zh", Name: "ZH", Catalog: "zhipuai", Key: "k", Chat: "http://127.0.0.1:9/v1"}
|
|
relay := Provider{ID: "rl", Name: "RL", Key: "k", Chat: "http://127.0.0.1:9/v1"}
|
|
none := settings.Settings{}
|
|
for _, c := range []struct {
|
|
p Provider
|
|
model string
|
|
want bool
|
|
}{
|
|
{free, "foo:free", true},
|
|
{free, "foo", false},
|
|
{free, "shared", true},
|
|
{paid, "shared", false},
|
|
{free, "cached", false},
|
|
{free, "nocost", false},
|
|
{free, "nobody-lists-this", false},
|
|
{plan, "plan-model", false},
|
|
{zhipu, "glm-4.7-flash", true},
|
|
{relay, "glm-4.7-flash", false},
|
|
} {
|
|
if got := c.p.PricedFree(none, c.model); got != c.want {
|
|
t.Errorf("%s's %s: PricedFree %v, want %v", c.p.ID, c.model, got, c.want)
|
|
}
|
|
}
|
|
|
|
zero, one := 0.0, 1.0
|
|
s := settings.Settings{ModelPrices: map[string]settings.ModelPrice{
|
|
// a paid price over 1000 tokens of input
|
|
"zf/foo:free": {Input: &zero, Output: &zero, CacheRead: &zero, CacheWrite: &zero, Tiers: []catalog.Tier{{Above: 1000, Input: 1}}},
|
|
// what the user pays their relay for it: nothing
|
|
"rl/glm-4.7-flash": {Input: &zero, Output: &zero, CacheRead: &zero, CacheWrite: &zero},
|
|
// every model of ZH costs them something
|
|
"zh/*": {Input: &one, Output: &one, CacheRead: &zero, CacheWrite: &zero},
|
|
}}
|
|
for _, c := range []struct {
|
|
p Provider
|
|
model string
|
|
want bool
|
|
}{
|
|
{free, "foo:free", false},
|
|
{relay, "glm-4.7-flash", true},
|
|
{zhipu, "glm-4.7-flash", false},
|
|
{free, "shared", true},
|
|
} {
|
|
if got := c.p.PricedFree(s, c.model); got != c.want {
|
|
t.Errorf("with the user's prices, %s's %s: PricedFree %v, want %v", c.p.ID, c.model, got, c.want)
|
|
}
|
|
}
|
|
}
|