Files
magpie/internal/provider/remote_magpie_test.go
T
yetone ba3c26dec4 providers: a Remote magpie provider uses another computer's shared magpie, each request translated at most once (Jorben on Discord: 远程 magpie / magpie 接力) — a custom provider pointed at another magpie has one API per address and couldn't know which API each model's own provider serves, so a request was translated on both computers (Chat → Messages here, then again there). magpie's /v1/models now tells each model's native_endpoints (the APIs its provider serves it on; none for a routing group) and its image input, and reads them, with max_output_tokens and supported_reasoning_levels, from a list; the new remote-magpie preset takes the other magpie's address however typed (host:port, /v1, /v1/messages) for all three APIs and lists all its models, its user's choice already. Add sheet tile with the address field and a hint to Settings → Share on local network; CLI: magpie provider add remote-magpie <key> url=http://<ip>:3425. Checked with two sandbox magpies over the LAN address with the key check on and a Messages-only fake upstream: Chat, Messages (streamed), count_tokens, Responses, a routing group and Gemini all reached it as /v1/messages, translated once. TestRemoteMagpieNativeAPI, TestFetchMagpieFields and TestRemoteMagpie fail without the change; remote-magpie.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass but for TestCursorPluginContext, which fails on main (1ce05f0) as well; click-scroll, old-webkit pass.
2026-10-01 01:35:18 +08:00

47 lines
1.5 KiB
Go

package provider
import (
"fmt"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// Another magpie is added by its address however it was typed, and
// speaks every API there: Chat and Responses at /v1, Messages at the root.
// Its whole list is offered, being already what its user exposed.
func TestRemoteMagpie(t *testing.T) {
azureHome(t)
for _, in := range []string{"192.168.1.20:3425", "http://192.168.1.20:3425/", "http://192.168.1.20:3425/v1", "http://192.168.1.20:3425/v1/messages"} {
p := normalize(Provider{Preset: RemoteMagpiePreset, Chat: in})
if p.Chat != "http://192.168.1.20:3425/v1" || p.Responses != p.Chat || p.Anthropic != "http://192.168.1.20:3425" {
t.Errorf("%q: %q %q %q", in, p.Chat, p.Responses, p.Anthropic)
}
}
// a custom provider's URL is left as it was
if p := normalize(Provider{Chat: "192.168.1.20:3425/v1"}); p.Anthropic != "" || p.Chat != "https://192.168.1.20:3425/v1" {
t.Errorf("custom: %+v", p)
}
if err := Save(Provider{ID: "office", Preset: RemoteMagpiePreset, Key: "sk-magpie-x", Chat: "http://192.168.1.20:3425"}); err != nil {
t.Fatal(err)
}
var ms []catalog.Model
for i := range manyModels + 6 {
ms = append(ms, catalog.Model{ID: fmt.Sprintf("p/m%d", i)})
}
if err := catalog.SaveLive("office", "http://192.168.1.20:3425/v1", ms); err != nil {
t.Fatal(err)
}
p, err := Find("office")
if err != nil {
t.Fatal(err)
}
if n := len(p.Exposed()); n != len(ms) {
t.Errorf("exposed %d of %d", n, len(ms))
}
if !p.Ready() || p.Icon != "magpie" {
t.Errorf("%+v", p)
}
}