A model a provider serves under its own id (a WorkBuddy kimi-k3-1, a relay's renamed gpt) had no price unless the user typed one, even when the user had already told magpie in the editor's "Same as" box which model it is. Its calls showed no API-price cost in Usage, window holds had no price to weigh, and `magpie model price` said unpriced. Now, when neither the user's prices, the provider's list nor models.dev's maker price covers a model, provider.SamePriceIn takes the maker's list price of the model it is the same as (settings.ModelSameAs), and the provider's price rate still applies. A price the user set, or a list that prices the model, always wins; nothing is inferred without a Same as. The same fallback is used by priceOf (Usage costs, re-priced when the ledger is read, so past calls pick it up), usage's apiPricer (window holds), the model editor's greyed list price, and `magpie model price`, which names where the price came from. The "Same as" tooltip says so in en, zh, zh-TW, ja and de. Run: - go test -p 1 -tags nogui ./internal/provider ./internal/usage ./internal/cli ./internal/gui (focused: TestSameAsPricesAnUnlistedModel, TestHoldsPriceTheModelItIsTheSameAs, TestModelEditorShowsTheSameAsPrice, TestModelPriceCmdSaysWhereThePriceCameFrom, plus the packages): ok - GUI (chromium + webkit): provider-same-as, i18n-keys, model-price-edit, 11/11 pass - gofmt -l clean; go vet -tags nogui for darwin, linux, windows: clean Broken by hand, each went red: - SamePriceIn dropped from priceOf: "kimi-k3-1 ... false; want $0.3" - usage's apiPricer fallback removed: "wasn't its API price: <nil>" - the GUI editor branch removed: "list <nil>" - the CLI source line disabled: TestModelPriceCmd... FAIL - the zh tooltip left untranslated: provider-same-as.test.cjs 0/2 A prefix-stripping branch passed when removed (MakerPrice already resolves vendor-prefixed ids like moonshotai/kimi-k3), so it was dropped. Not tried: a real WorkBuddy account's usage after the change. Full suite: SUITE_LINE
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package gui
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// #2344: the model editor greys in the price a model is costed at. A
|
|
// model no list prices, with a Same as, is costed at the maker's price of
|
|
// the model it is the same as, so the editor shows that one, beside the
|
|
// Same as box that says why; one with none still shows none.
|
|
func TestModelEditorShowsTheSameAsPrice(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
|
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
|
|
os.WriteFile(catalog.CachePath(), []byte(`{
|
|
"moonshotai":{"id":"moonshotai","models":{"kimi-k3":{"id":"kimi-k3","cost":{"input":0.6,"output":2.5}}}}}`), 0o644)
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"kimi-k3-1", "other"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := settings.Load()
|
|
s.ModelSameAs = map[string]string{"relay/kimi-k3-1": "kimi-k3"}
|
|
if err := settings.Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, err := provider.Find("relay")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, m := range providerInfo(*p, nil).Models {
|
|
switch m.ID {
|
|
case "kimi-k3-1":
|
|
if m.List == nil || m.List.Input != 0.6 || m.Same != "kimi-k3" {
|
|
t.Errorf("kimi-k3-1: list %+v, same %q; want Kimi K3's $0.6", m.List, m.Same)
|
|
}
|
|
case "other":
|
|
if m.List != nil {
|
|
t.Errorf("a model with no Same as shows a list price: %+v", m.List)
|
|
}
|
|
}
|
|
}
|
|
}
|