Alibaba sells two Token Plans, both with sk-sp- keys, and a key works only on its own host. qwen-token-plan is the Qwen AI platform's (token-plan.maas.qianwenaiapi.com), but its website and keys links pointed at Bailian's console. Bailian's own plan (token-plan.cn-beijing.maas.aliyuncs.com) had no preset. What changed: - presets: new bailian-token-plan (chat /compatible-mode/v1, Anthropic /apps/anthropic, decide on /compatible-mode/v1/systemone, models from the docs' list, shared with qwen-token-plan as alibabaPlanModels). qwen-token-plan's links now point at the Qwen AI platform. New qwen-decision for Qwen's pay-as-you-go decision model at maas.qianwenaiapi.com/compatible-mode/v1/systemone. bailian-decision shows the Bailian icon instead of Qwen's. - decide: bailianDecides also matches the bare maas.qianwenaiapi.com host. A chat preset that also decides on a Bailian/Qwen host (bailianApart) lists decision-model-preview as its only decision model, so it is offered for routing groups and never given to an agent as a chat model. - gateway: dashScope() covers bailian-token-plan and maas.qianwenaiapi.com. - CLI help, docs/reference.md and the import docs (en, zh, ja) name the new preset. Usage: neither plan's docs give a usage or quota API; the remaining quota is only on the console (百炼控制台 Token Plan > 我的订阅, Qwen 工作台 token-plan/individual), which needs a browser session. So no usage card is added. An exhausted plan's 429 insufficient_quota is already read as out of credit. Not tried against the real API: no Bailian or Qwen key was available. The stand-in is an httptest server copying the docs' systemone curl (Bearer sk-sp-, model decision-model-preview) and its error table (401 on a wrong key, 422 on a bad body). qwen-decision sends "Authorization: Bearer <key>"; the Qwen doc's curl shows the bare key, which is untested. Run: - go test -tags nogui -count=1 ./... (temp HOME) - TestBailianTokenPlan, TestQwenDecisionPreset and TestDashScopeHosts fail with the old decide.go and gateway.go swapped in - gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui on . internal/provider, internal/gateway, internal/gui - GUI: system-one, add-sheet, gateway-decide-info, routing-kind tests in chromium and webkit (20 pass)
92 lines
2.8 KiB
Go
92 lines
2.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// The editor receives an authoritative list, even empty, so a Jev Router
|
|
// chat model on a remote isn't guessed to be a System One model.
|
|
func TestRemoteMagpieDecisionPicker(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := provider.Save(provider.Provider{ID: "office", Preset: provider.RemoteMagpiePreset, Chat: "http://127.0.0.1:1", Key: "remote-key"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _ := provider.Find("office")
|
|
for _, decisions := range [][]catalog.Model{
|
|
{{ID: "judge/custom", Decides: true}},
|
|
nil,
|
|
} {
|
|
ms := append([]catalog.Model{{ID: "relay/typesafe/jev-router"}}, decisions...)
|
|
if err := catalog.SaveLive(p.ID, p.Chat, ms); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := providerInfo(*p, nil)
|
|
want := []string{"relay/typesafe/jev-router"}
|
|
for _, m := range decisions {
|
|
want = append(want, m.ID)
|
|
}
|
|
var got []string
|
|
for _, m := range out.Models {
|
|
got = append(got, m.ID)
|
|
}
|
|
if !slices.Equal(got, want) {
|
|
t.Fatalf("editor models after refresh: %v; want %v", got, want)
|
|
}
|
|
if out.Deciders == nil || len(*out.Deciders) != len(decisions) {
|
|
t.Fatalf("editor decision list: %v", out.Deciders)
|
|
}
|
|
if len(decisions) > 0 && !slices.Equal(*out.Deciders, []string{"judge/custom"}) {
|
|
t.Fatalf("editor decisions: %v", *out.Deciders)
|
|
}
|
|
b, err := json.Marshal(out)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var fields map[string]json.RawMessage
|
|
json.Unmarshal(b, &fields)
|
|
if len(decisions) == 0 && string(fields["deciders"]) != "[]" {
|
|
t.Fatalf("empty decisions omitted: %s", b)
|
|
}
|
|
if out.Decide != "http://127.0.0.1:1/v1" || out.Chat != out.Decide {
|
|
t.Fatalf("remote API bases: %+v", out)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Bailian's Token Plan (#1506): the editor is told its one decision model
|
|
// beside the plan's chat models, so a routing group can pick it and no
|
|
// agent is offered it.
|
|
func TestBailianTokenPlanDecisionPicker(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
p, err := provider.FromPreset("bailian-token-plan")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p.Key = "sk-sp-1"
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
saved, _ := provider.Find(p.ID)
|
|
if err := catalog.SaveLive(saved.ID, saved.Chat, []catalog.Model{{ID: "qwen3.8-max"}, {ID: "glm-5.3"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := providerInfo(*saved, nil)
|
|
if out.Deciders == nil || !slices.Equal(*out.Deciders, []string{provider.BailianDecision}) {
|
|
t.Fatalf("editor decisions: %v", out.Deciders)
|
|
}
|
|
var got []string
|
|
for _, m := range out.Models {
|
|
got = append(got, m.ID)
|
|
}
|
|
if !slices.Equal(got, []string{"qwen3.8-max", "glm-5.3", provider.BailianDecision}) {
|
|
t.Fatalf("editor models: %v", got)
|
|
}
|
|
}
|