nb5p on Discord: (1) a custom provider set to Responses had its models
wired into dsh on magpie's Chat Completions route (`magpie`), so dsh sent
Chat and magpie translated; (2) in dsh's models, mygateway/gpt-6.1-sol was
"GPT-6.1 Sol" while mygateway/gpt-6.1-terra was "GPT-6.1 Terra · MyGateway".
Cause 1: Provider.Native never read BaseAPI, the API the user gave the
Base URL as. Detect fills in every API that answers, so a relay picked as
Responses also had a Chat URL, and Native returned Chat (out[0]). Native
now takes BaseAPI after the vendor rules (ResponsesFirst, MessagesFirst),
when the provider serves it. dsh supports it: dsh 0.2.1-rc.2 bundles
@earendil-works/pi-ai, whose KnownApi includes "openai-responses", and
magpie already has the `magpie-responses` route (dshKinds). Siblings
reading m.APIs from magpieModels move with it: dsh, Pi, omp, droid,
Grok Build.
Cause 2: provider.Labels counted collisions over models and routing
groups together. A model two providers serve gets an auto group with the
model's name, so the shown model collided with its own group and kept
"· Provider" (terra: served by a second provider too, hidden for dsh;
sol: one provider). Models and groups are counted apart now: a model
keeps its suffix only when another model reads the same, and a group
named like anything else keeps "· routing group". Labels feeds every
agent's list, so this holds for all of them.
Not changed: the gateway's usable() still orders a translated request
Chat first and doesn't read BaseAPI (#4508).
Tests (each red on the old code, broken by hand in a worktree on
origin/main: all new cases red; reverting only Native red on the route,
reverting only Labels red on terra's name; the old dsh output reproduced
the report exactly):
- internal/agent TestDshCustomResponsesProvider (new): both models on
magpie-responses, none on magpie, named "GPT-6.1 Sol"/"GPT-6.1 Terra".
- internal/provider native_test: Responses picked beside Chat, Chat
picked, Responses picked for a Claude where Messages is served, and
Responses picked with no Responses URL.
- plainnames/plainown_groups/suffix_mode expectations updated to the rule.
Run on mote, at this change on 7fe191cec (the pushed head is the same
change rebased on a newer origin/main, 6f435677c; not re-run there):
go test -tags nogui -count=1 -timeout 45m ./internal/provider
./internal/agent ./internal/gateway ./internal/cli ./internal/gui:
provider ok 170s, agent ok 303s, gateway ok 797s, cli ok 53s; gui FAIL
TestColdTurnsTaken only (0.00s, a test race untouched by this change,
filed #4510). gofmt -l clean. Still running at push: TestColdTurnsTaken
-count=20 and GOOS=linux/windows go vet ./... on mote, and the test on
origin/main alone.
Not tried: a real dsh session against a real Responses relay; nb5p's
own providers.json (the second provider serving terra is inferred from
the suffix); the GUI suite (no GUI file changed); the full ./... suite.
57 lines
3.0 KiB
Go
57 lines
3.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// Native is the API a client does best to ask a model on, for the gateway
|
|
// to relay it as it is.
|
|
func TestNative(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"))
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
// Copilot's model list says which APIs serve each model
|
|
if err := catalog.SaveLive("copilot", "https://api.githubcopilot.com", []catalog.Model{
|
|
{ID: "gpt-5.5", APIs: []string{"responses"}}, {ID: "claude-sonnet-5", APIs: []string{"chat", "anthropic"}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
openai := Provider{ID: "openai", Chat: "https://api.openai.com/v1", Responses: "https://api.openai.com/v1"}
|
|
copilot := Provider{ID: "copilot", Chat: "https://api.githubcopilot.com", Responses: "https://api.githubcopilot.com", Anthropic: "https://api.githubcopilot.com"}
|
|
for _, c := range []struct {
|
|
name string
|
|
p Provider
|
|
model string
|
|
want Protocol
|
|
}{
|
|
{"chat only", Provider{ID: "relay", Chat: "https://relay.test/v1"}, "glm-4.6", Chat},
|
|
{"responses only", Provider{ID: "resp", Responses: "https://resp.test/v1"}, "m", Responses},
|
|
{"ChatGPT sign-in", Provider{ID: "codex", Responses: CodexBase, Account: &Account{Agent: "codex"}}, "gpt-5.5", Responses},
|
|
{"GPT on OpenAI's API", openai, "gpt-5.5", Responses},
|
|
{"o-series on OpenAI's API", openai, "o3", Responses},
|
|
{"other on OpenAI's API", openai, "whisper-x", Chat},
|
|
{"Chat and Responses elsewhere", Provider{ID: "both", Chat: "https://x.test/v1", Responses: "https://x.test/v1"}, "gpt-5.5", Chat},
|
|
// the API the user gave a custom provider's Base URL as, where a
|
|
// Chat URL was found beside it (nb5p on Discord)
|
|
{"Responses picked beside Chat", Provider{ID: "mygateway", Chat: "https://x.test/v1", Responses: "https://x.test/v1", BaseAPI: "responses"}, "gpt-6.1-sol", Responses},
|
|
{"Chat picked beside Responses", Provider{ID: "mygateway", Chat: "https://x.test/v1", Responses: "https://x.test/v1", BaseAPI: "chat"}, "gpt-6.1-sol", Chat},
|
|
{"Responses picked, Claude on Messages", Provider{ID: "mygateway", Responses: "https://x.test/v1", Anthropic: "https://x.test", BaseAPI: "responses"}, "claude-sonnet-5", Anthropic},
|
|
{"Responses picked, no Responses URL", Provider{ID: "mygateway", Chat: "https://x.test/v1", BaseAPI: "responses"}, "m", Chat},
|
|
{"anthropic only", Provider{ID: "anthropic", Anthropic: "https://api.anthropic.com"}, "claude-sonnet-5", Anthropic},
|
|
{"Copilot GPT", copilot, "gpt-5.5", Responses},
|
|
{"Copilot Claude", copilot, "claude-sonnet-5", Anthropic},
|
|
{"Claude Code", Provider{ID: "claude", Anthropic: "https://api.anthropic.com", Account: &Account{Agent: "claude"}}, "claude-sonnet-5", ""},
|
|
{"nothing", Provider{ID: "none"}, "m", ""},
|
|
} {
|
|
if got := c.p.Native(c.model); got != c.want {
|
|
t.Errorf("%s: %q, want %q", c.name, got, c.want)
|
|
}
|
|
}
|
|
}
|