A Discord user's POST /v1/decisions was answered 404 ("magpie serves
/v1/chat/completions, ..."). It is OpenAI's Decisions API (gpt-6-luna):
one input, up to 400 questions, typed answers, input tokens billed only.
The shape was taken from openai-python (resources/decisions.py,
types/decision_create_params.py, types/decision.py, added in #4033 on
10-06) and the Decisions guide, not guessed: POST /v1/decisions, a JSON
body of model, input (a string or messages/items with input_text,
input_image as a data or http(s) URL, JSON parts; function and custom
tool calls and their outputs), questions (predicate / choice / score),
and optional prompt_cache_key, prompt_cache_options, safety_identifier.
The answer is {answers, model, usage}, not streamed; usage.input_tokens
includes input_tokens_details.cached_tokens and cache_write_tokens. The
Azure client sends it on the v1 API (/openai/v1/decisions), the model in
the body.
- decide (decisions.go) goes through serveRetrieval as embeddings and
rerank do, body as sent with only model changed. So a disabled model,
a key's models, accounts and spent limits, pause rules, keys/accounts
of the provider, masking and the Routing page hold here as on every
route.
- Only a provider canDecide takes is sent it: an OpenAI API key on
api.openai.com, Azure OpenAI (IsAzure, at its OpenAIBase, so
/openai/v1/decisions with api-key), or another magpie. Anyone else (a
relay, a plugin, a ChatGPT sign-in) gets a 400 that says who serves
it, checked in serveRetrieval's try loop beside the no-OpenAI-API
check (refusingRetrieval), never the vendor's 404; a group moves on.
- A bare gpt-6-luna is a kind group "decision" (servesDecision), so a
relay that lists the same id is never its member.
- Usage is recorded as "decisions" (countedRetrieval): input less the
cached and cache-written tokens, those as CacheRead/CacheWrite, and
no output, so gpt-6-luna's own models.dev rates price it as OpenAI
bills ($0.10/1M input, cache read/write at their rates).
- /decisions joins the one-port client prefixes, another magpie's URL
suffixes, the 404's route list and info's apis. The readonly, LAN
and CORS guard tests list the route.
- native_endpoints is left alone: it names the chat APIs a model is
relayed on (Cursor's names, a remote's API choice).
- docs: gateway-routing.md has a Decisions row; reference.md a section.
Run on mote at this tree (mote-run): gofmt -l clean; go vet of gateway
and provider; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet
./...; go build ./..., linux nogui and windows builds ok;
go test -count=1 -timeout 45m ./internal/gateway ./internal/provider
./internal/usage: ok (gateway 413s, provider 88s, usage 18s).
Red on the old code (e0930b1de, the new tests copied in): every
TestDecisions* is red with magpie's 404.
Broken by hand, each red: refuses always "" (the relay is sent it:
TestDecisionsRefusedWhereNotServed); the cache split not read
(Input 1200, CacheRead 0: TestDecisionsReachOpenAIAndAzure); canDecide
without the api.openai.com check (TestCanDecide, the relay sent it);
/v1/decisions out of the remote suffixes (TestRemoteMagpie).
Not tried: a real OpenAI Decisions request, or a real Azure resource.
Tests reach only httptest servers (OpenAI's host through the provider's
proxy).
60 lines
1.9 KiB
Go
60 lines
1.9 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",
|
|
"http://192.168.1.20:3425/v1/systemone",
|
|
"http://192.168.1.20:3425/v1/embeddings",
|
|
"http://192.168.1.20:3425/v1/rerank",
|
|
"http://192.168.1.20:3425/v1/decisions",
|
|
"http://192.168.1.20:3425/v1/images/generations",
|
|
"http://192.168.1.20:3425/v1/images/edits",
|
|
"http://192.168.1.20:3425/v1/videos",
|
|
"http://192.168.1.20:3425/v1/messages/count_tokens",
|
|
} {
|
|
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" || p.Decide != p.Chat {
|
|
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)
|
|
}
|
|
}
|