magpieModels gave a routing group no native API, since its members may each want another. Pi, omp and droid then asked every group on Chat Completions, and dsh put it on its Chat route, even a group of GPT members all served on Responses. The gateway translated each answer from Responses to Chat, and that translation holds a tool call's arguments until the call ends (#613), so Pi's Code Mode saw no code until the whole call had been generated. A group now has APIs ["responses"] when every member, nested groups' included, is served best on Responses (allResponses over the group's members, by Provider.Native). Any other group keeps none: one with a Chat member, and a Messages-only group too, as the gateway knows whether a Claude thinks adaptively by its own model id, not the group's. dsh moves a start on such a group to its Responses route (dshStartOnItsRoute); a dsh session resumed on it asks for the model once, as for any model that moved routes. The rest of the request (a protocol picked per group, conversion shown per request) is not in this commit. Verified: - TestPiModelsAskedOnTheirNativeAPI: auto-gpt-5-5, a GPT group and a group of that group get openai-responses; a group with a Chat member and one of Messages-only members get none. Without the route.go change it fails for the three Responses groups. - TestOmpModelsAskedOnTheirNativeAPI: the same for omp. - TestGroupOnResponsesRelaysArgumentDeltas (gateway): a group of two Responses-only members asked on /v1/responses relays each function_call_arguments.delta as the vendor sent it, on /responses. It guards what this change relies on, and passed before it too. - go test ./internal/agent ./internal/provider, gofmt -l, GOOS=linux and windows go vet -tags nogui. - Not tried with a real Pi against a real group.
101 lines
3.9 KiB
Go
101 lines
3.9 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// omp asks each model on the API its provider serves it on, as Pi does: a
|
|
// Claude over Chat lost its thinking's signatures between tool turns. A
|
|
// Messages-only provider's models go on anthropic-messages at the gateway,
|
|
// a Responses-only one's on openai-responses, and a Chat provider's stay on
|
|
// the provider's openai-completions, keyless. A group goes on
|
|
// openai-responses when all its members are best there (#1594), else stays.
|
|
func TestOmpModelsAskedOnTheirNativeAPI(t *testing.T) {
|
|
home := syncHome(t)
|
|
was := ompVersion
|
|
ompVersion = func() string { return "16.3.5" }
|
|
t.Cleanup(func() { ompVersion = was })
|
|
for _, p := range []provider.Provider{
|
|
{ID: "resp", Name: "Resp", Key: "k", Responses: "http://127.0.0.1:1/v1", Models: []string{"grok-5", "gpt-5.5"}},
|
|
{ID: "openai", Name: "OpenAI", Key: "k", Chat: "https://api.openai.com/v1", Responses: "https://api.openai.com/v1", Models: []string{"gpt-5.5"}},
|
|
{ID: "anth", Name: "Anth", Key: "k", Anthropic: "http://127.0.0.1:1", Models: []string{"claude-sonnet-5", "claude-sonnet-4-5", "kimi-k3"}},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "mixed", Name: "Mixed", Members: []string{"resp/grok-5", "relay/glm-4.6"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var live []catalog.Model
|
|
for _, id := range []string{"claude-sonnet-5", "claude-sonnet-4-5", "kimi-k3"} {
|
|
live = append(live, catalog.Model{ID: id, Efforts: []string{"low", "high", "max"}})
|
|
}
|
|
if err := catalog.SaveLive("anth", "http://127.0.0.1:1", live); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := omp(home).Field("model").Set("magpie/anth/claude-sonnet-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(filepath.Join(home, ".omp", "agent", "models.yml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var file map[string]any
|
|
if err := yaml.Unmarshal(b, &file); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pm := file["providers"].(map[string]any)["magpie"].(map[string]any)
|
|
if pm["api"] != "openai-completions" || pm["baseUrl"] != gatewayV1() || pm["auth"] != "none" {
|
|
t.Fatalf("provider: %v", pm)
|
|
}
|
|
entries := map[string]map[string]any{}
|
|
for _, raw := range pm["models"].([]any) {
|
|
m := raw.(map[string]any)
|
|
entries[m["id"].(string)] = m
|
|
}
|
|
for id, want := range map[string]any{
|
|
"resp/grok-5": "openai-responses",
|
|
"relay/glm-4.6": nil,
|
|
"anth/claude-sonnet-5": "anthropic-messages",
|
|
"anth/claude-sonnet-4-5": "anthropic-messages",
|
|
"anth/kimi-k3": "anthropic-messages",
|
|
"group/auto-gpt-5-5": "openai-responses",
|
|
"group/mixed": nil,
|
|
} {
|
|
e, ok := entries[id]
|
|
if !ok {
|
|
t.Errorf("%s not listed: %s", id, b)
|
|
} else if e["api"] != want {
|
|
t.Errorf("%s: api %v, want %v", id, e["api"], want)
|
|
}
|
|
}
|
|
// omp posts to baseUrl + /v1/messages; the Claude that refuses a
|
|
// thinking budget thinks adaptively, the others on a budget alone
|
|
for id, mode := range map[string]string{"anth/claude-sonnet-5": "anthropic-adaptive", "anth/claude-sonnet-4-5": "budget", "anth/kimi-k3": "budget"} {
|
|
e := entries[id]
|
|
if e["baseUrl"] != gateway.URL() {
|
|
t.Errorf("%s: baseUrl %v, want %s", id, e["baseUrl"], gateway.URL())
|
|
}
|
|
// and, for omp 16.3.5, its efforts stop at xhigh, the gateway's way
|
|
// to max: it turns the whole models.yml away over a max
|
|
th, _ := e["thinking"].(map[string]any)
|
|
if th["mode"] != mode || fmt.Sprint(th["efforts"]) != "[low high xhigh]" {
|
|
t.Errorf("%s: thinking %v, want mode %s, efforts [low high xhigh]", id, e["thinking"], mode)
|
|
}
|
|
}
|
|
for _, id := range []string{"resp/grok-5", "relay/glm-4.6"} {
|
|
if _, ok := entries[id]["baseUrl"]; ok {
|
|
t.Errorf("%s keeps the provider's baseUrl: %v", id, entries[id])
|
|
}
|
|
}
|
|
}
|