provider, plugin: a plugin can serve System One for its provider, and the models it marks are a routing group's classifier (#1514, FourLeafTec)
A plugin had no way to say its provider answers TypeSafe's System One,
so a free decision model a plugin reaches (mu-zi-lee/magpie-our-free-model)
could only be listed as a chat model.
Now the plugin's config hook sets `decide: true` on the provider, and
`decides: true` on a model, in the config hook or on the models hook's
list. host.js passes both through (plugin.Provider.Decide,
plugin.Model.Decides). pluginProvider sets the provider's Decide to its
own base, plugin://<id>/v1, so System One is asked at {baseURL}/systemone
through the loader's fetch with the account's sign-in: pluginFetch sends
nowhere but the loader's host, so an address the plugin named itself
couldn't be reached. AskSystemOne now sends with Provider.Do, as the
gateway's classifier already did, so the editor's test goes through the
fetch too (Do is client.Do for every provider without an account).
decide.go treats a plugin provider's decision models as the ones it marks
plus Jev's by name (jev-*): kept from agents, refused for chat ("only
decides"), refused as a group member, offered as a group's classifier
(Deciders, DecisionModels, Jev). A mark without `decide` on the provider
changes nothing. Docs: site plugins page (en, zh, ja) and
docs/subsystems/provider-plugins.md.
Thanks to FourLeafTec, whose reference commit (bc0b3fee in their fork)
proposed the two fields and the plugin base; this is written afresh.
Run:
- internal/gateway TestPluginServesSystemOne and
TestPluginMarksWithoutDecide, through the real bun plugin host with the
fake plugin (FAKE_DECIDE). Red with host.js, plugins.go and decide.go
reverted ("Decide = \"\""), with only host.js reverted, and with only
decide.go reverted (no classifiers, offered to agents, chat to one 200).
- go test -tags nogui ./... (temp HOME): every package ok; internal/gateway
hit the 10m default at load ~140 in TestLargeRequestEndpoints, then
passed alone with -timeout 40m (548s).
- gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui on
internal/plugin, internal/provider, internal/gateway.
- Real use: a nogui build in a sandbox HOME on 127.0.0.1:3612, a local
plugin declaring decide with judge-x marked, a fake vendor on 3613.
`magpie group rule add ... classifier=dec1514/judge-x` saved; judge-x
was not in /v1/models and not accepted as a member; a turn to the group
asked /v1/systemone judge-x (levels, then intent) with the plugin's key
and its fetch's own header, then went to chat-b; chat to judge-x
answered 400 "only decides".
- No GUI change: a plugin's editor is the account editor, which has no
address fields.
Co-authored-by: FourLeafTec <5875432+FourLeafTec@users.noreply.github.com>
This commit is contained in:
@@ -46,6 +46,12 @@ WorkBuddy's check-in ([`workbuddy_checkin.go`](../../internal/provider/workbuddy
|
||||
|
||||
Qoder plugins without `auth.checkin` still use [`qoder_checkin.go`](../../internal/provider/qoder_checkin.go) through the plugin's fetch. The server's `CLAIMABLE` status decides whether to claim; the local `[startAt, endAt)` check only recognizes an already-claimed campaign and its expiry, including one that crosses Beijing midnight. Successful results keep the active campaign's end in the optional `until` field of `qoder-checkin.json`. Scheduled checks reuse results from the same Beijing day for at most 30 minutes and never past that end, so a long campaign cannot hide new or reset campaigns indefinitely. The existing loop looks every 30 minutes and on a Beijing day change; a midnight refresh saves today's result for the Usage card and TUI. An `inactive` result is now asked again after 30 minutes rather than settled for the day; failures retain their existing retry schedule. A manual check-in always asks immediately. Saved results without `until` remain readable and use the same 30-minute refresh, with no migration needed. Other vendors and plugins with their own check-in retain their daily settlement.
|
||||
|
||||
## A plugin's decision API
|
||||
|
||||
A plugin can serve TypeSafe's System One for its provider (#1514). Its `config` hook sets `decide: true` on the provider, and `decides: true` on a model that answers questions rather than a conversation, in the `config` hook or on the `models` hook's list. The host passes both through (`plugin.Provider.Decide`, `plugin.Model.Decides`). [`pluginProvider`](../../internal/provider/plugins.go) then sets the provider's `Decide` to `plugin://<id>/v1`, its own base: `pluginFetch` sends nowhere but the loader's host, so a decision address of the plugin's own couldn't be reached. `AskSystemOne` and the gateway's classifier post `/v1/systemone` with `Provider.Do`, which reaches the loader's `fetch` as `{baseURL}/systemone` with the account's sign-in.
|
||||
|
||||
In [`decide.go`](../../internal/provider/decide.go) a plugin provider's decision models are the ones it marks (`pluginMarks`, read from the plugin's current listing) and Jev's by name (`jev-*`). They are kept from agents (`isDecision` in `buildEntries`), refused for chat ("only decides"), refused as a group member, and offered as a group's classifier (`Deciders`, `DecisionModels`). A mark counts only when the provider says `decide`; without it every model stays one to chat with. A plugin provider's editor (the account editor) has no address fields, so this address is never typed; the GUI marks the decision models from `deciders`.
|
||||
|
||||
## Two plugins for one provider id
|
||||
|
||||
The host runs one plugin per provider id. When two installed plugins have `auth` hooks for the same id, such as a third-party plugin and the user's own copy added by its folder, `auths()` in `host.js` takes the one picked for that id in `plugins.json`'s `prefer` map (provider id → spec). Without a pick it takes the last one in the list, as OpenCode does. Only the serving plugin's `provider.models` hook runs for that id. Every plugin's `config` hook still runs, so another plugin can still add models or a name to `config.provider[id]`.
|
||||
@@ -118,6 +124,8 @@ The GUI's plugin integration includes `subOf`, `pluginSubs`, and `startPluginSig
|
||||
|
||||
Gateway parity tests in [`plugin_parity_test.go`](../../internal/gateway/plugin_parity_test.go) and other `plugin_*_test.go` files compare or exercise plugin paths. A built-in test alone does not establish moved-user behavior. Inspect each test's fixture to confirm that it covers the provider and operation being changed.
|
||||
|
||||
[`plugin_decide_test.go`](../../internal/gateway/plugin_decide_test.go) runs the fake plugin (`FAKE_DECIDE`) with a decision API: its marked and `jev-*` models are classifiers and not offered to agents, chat to one is refused, a group saves one as classifier and not as member, and each classifier's question reaches the fake vendor at `/v1/systemone` through the plugin's fetch. With `FAKE_DECIDE=models` the marks without `decide` change nothing.
|
||||
|
||||
[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
|
||||
|
||||
[`plugin_cliproxy_test.go`](../../internal/plugin/plugin_cliproxy_test.go)'s `TestPluginHostTakesANewProxy` starts a real host without a proxy, sets one, and checks that a program the plugin starts gets it. `plugin-signed-out-account.test.cjs` covers a moved Grok account signed out while in use and as the agent's own, in Chromium and WebKit, en and zh, 420 and 1100 wide.
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// decideUp is the fake plugin's vendor serving conversations and System
|
||||
// One both: it keeps the path, model and sign-in of each request.
|
||||
type decideUp struct {
|
||||
mu sync.Mutex
|
||||
asked []string // "path model authorization"
|
||||
}
|
||||
|
||||
func (u *decideUp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
var q struct{ Model string }
|
||||
json.Unmarshal(b, &q)
|
||||
u.mu.Lock()
|
||||
u.asked = append(u.asked, r.URL.Path+" "+q.Model+" "+r.Header.Get("Authorization"))
|
||||
u.mu.Unlock()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.URL.Path {
|
||||
case "/v1/systemone":
|
||||
io.WriteString(w, `{"model":"`+q.Model+`","answers":{"levels":{"type":"noul","noul":0},"intent":{"type":"choice","choice":"bug","confidence":0.9}}}`)
|
||||
case "/v1/chat/completions":
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
io.WriteString(w, sse(`data: {"id":"c","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"from the plugin"},"finish_reason":"stop"}]}`, `data: [DONE]`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *decideUp) seen() []string {
|
||||
u.mu.Lock()
|
||||
defer u.mu.Unlock()
|
||||
return slices.Clone(u.asked)
|
||||
}
|
||||
|
||||
// A plugin that says decide on its provider serves System One for it
|
||||
// (#1514, FourLeafTec): its marked models and Jev's by name are offered as
|
||||
// a routing group's classifier, kept from agents, and asked through the
|
||||
// plugin's own fetch at its base /systemone.
|
||||
func TestPluginServesSystemOne(t *testing.T) {
|
||||
t.Setenv("FAKE_DECIDE", "1")
|
||||
up := &decideUp{}
|
||||
pid := besideFake(t, "fakeco", up)
|
||||
p, err := provider.Find(pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Decide != "plugin://fakeco/v1" {
|
||||
t.Fatalf("Decide = %q", p.Decide)
|
||||
}
|
||||
// fake-clef is marked in the config hook, fake-judge on the models
|
||||
// hook's list, jev-9 is Jev by its name
|
||||
deciders := map[string]bool{}
|
||||
for _, e := range provider.Deciders() {
|
||||
deciders[e.ID] = true
|
||||
}
|
||||
for _, m := range []string{"fake-clef", "fake-judge", "jev-9"} {
|
||||
if !deciders[pid+"/"+m] {
|
||||
t.Errorf("%s is no classifier: %v", m, deciders)
|
||||
}
|
||||
if offered(pid + "/" + m) {
|
||||
t.Errorf("%s is offered to agents", m)
|
||||
}
|
||||
}
|
||||
if deciders[pid+"/fake-1"] {
|
||||
t.Error("fake-1, a chat model, is a classifier")
|
||||
}
|
||||
if !offered(pid + "/fake-1") {
|
||||
t.Error("fake-1 isn't offered to agents")
|
||||
}
|
||||
s := New()
|
||||
if code, out := postAs(t, s, "", `{"model":"`+pid+`/fake-1","messages":[{"role":"user","content":"hi"}]}`); code != 200 || !strings.Contains(out, "from the plugin") {
|
||||
t.Fatalf("chat: %d %s", code, out)
|
||||
}
|
||||
if code, out := postAs(t, s, "", `{"model":"`+pid+`/fake-clef","messages":[{"role":"user","content":"hi"}]}`); code != 400 || !strings.Contains(out, "only decides") {
|
||||
t.Fatalf("chat to a decision model: %d %s", code, out)
|
||||
}
|
||||
// a group's classifier, and never a member
|
||||
g := provider.Group{ID: "d", Members: []string{pid + "/fake-1"}, Classifier: pid + "/fake-clef",
|
||||
Rules: []provider.Rule{{Use: pid + "/fake-1", Intent: "bug"}}}
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SaveGroup(provider.Group{ID: "e", Members: []string{pid + "/fake-judge"}}); err == nil || !strings.Contains(err.Error(), "classifier") {
|
||||
t.Fatalf("a decision model saved as a member: %v", err)
|
||||
}
|
||||
for _, m := range []string{"fake-clef", "fake-judge", "jev-9"} {
|
||||
if v, err := s.askClassifier(pid+"/"+m, []string{"feature", "bug"}, before{}, false, "fix this"); err != nil || v.Intent != "bug" {
|
||||
t.Fatalf("classify with %s: %+v %v", m, v, err)
|
||||
}
|
||||
}
|
||||
var decided []string
|
||||
for _, a := range up.seen() {
|
||||
if strings.HasPrefix(a, "/v1/systemone ") {
|
||||
decided = append(decided, a)
|
||||
}
|
||||
}
|
||||
want := []string{"/v1/systemone fake-clef Bearer k1", "/v1/systemone fake-judge Bearer k1", "/v1/systemone jev-9 Bearer k1"}
|
||||
// each is asked whether the intents are levels, then which it is
|
||||
if !slices.Equal(slices.Compact(decided), want) {
|
||||
t.Fatalf("the plugin's vendor was asked %v, want %v", up.seen(), want)
|
||||
}
|
||||
// and the editor's test asks the same way
|
||||
if err := p.AskSystemOne(t.Context(), "fake-clef"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin that marks models without saying decide has no decision API:
|
||||
// its models stay ones to chat with, as before #1514.
|
||||
func TestPluginMarksWithoutDecide(t *testing.T) {
|
||||
t.Setenv("FAKE_DECIDE", "models")
|
||||
pid := besideFake(t, "fakeco", &decideUp{})
|
||||
p, err := provider.Find(pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Decides() {
|
||||
t.Fatalf("Decide = %q", p.Decide)
|
||||
}
|
||||
for _, e := range provider.Deciders() {
|
||||
if e.Provider.ID == pid {
|
||||
t.Fatalf("%s is a classifier", e.ID)
|
||||
}
|
||||
}
|
||||
for _, m := range []string{"fake-clef", "jev-9", "fake-1"} {
|
||||
if !offered(pid + "/" + m) {
|
||||
t.Errorf("%s isn't offered to agents", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// offered reports whether agents are offered the model id.
|
||||
func offered(id string) bool {
|
||||
return slices.ContainsFunc(provider.Catalog(), func(e provider.Entry) bool { return e.ID == id })
|
||||
}
|
||||
@@ -1155,6 +1155,9 @@ async function info(id, key, strict) {
|
||||
options: { ...(cfg?.options ?? {}) },
|
||||
npm: cfg?.npm ?? md?.npm,
|
||||
api: cfg?.api ?? md?.api,
|
||||
// magpie's own field: the plugin serves a decision API (System One)
|
||||
// for this provider, asked at its base /systemone through its fetch
|
||||
decide: cfg?.decide === true,
|
||||
models: {},
|
||||
}
|
||||
if (md) for (const m of Object.values(md.models ?? {})) out.models[m.id] = fromModelsDev(md, m)
|
||||
@@ -1179,6 +1182,8 @@ async function info(id, key, strict) {
|
||||
...(m.modalities?.input ? { input: Object.fromEntries(["text", "image", "audio", "video", "pdf"].map((k) => [k, m.modalities.input.includes(k)])) } : {}),
|
||||
},
|
||||
variants: m.variants ?? was?.variants ?? {},
|
||||
// magpie's own mark: a decision model, answering System One
|
||||
...(typeof m.decides === "boolean" ? { decides: m.decides } : was?.decides !== undefined ? { decides: was.decides } : {}),
|
||||
}
|
||||
}
|
||||
const server = auths().get(id)?.spec
|
||||
@@ -1307,6 +1312,7 @@ async function providers({ proxies } = {}) {
|
||||
icon: iconOf(a),
|
||||
usage: typeof a.auth.usage === "function",
|
||||
checkin: typeof a.auth.checkin === "function",
|
||||
decide: p.decide === true,
|
||||
maxConcurrency: concurrencyOf(a),
|
||||
signedIn: keys.length > 0,
|
||||
authType: first?.type ?? "",
|
||||
@@ -1346,6 +1352,9 @@ async function providers({ proxies } = {}) {
|
||||
rateWas: rateOf(m.rateWas),
|
||||
// run fast when the request's service_tier is priority (Cursor's)
|
||||
fast: m.fast === true,
|
||||
// a decision model (System One's), hidden from agents and
|
||||
// offered as a routing group's classifier
|
||||
decides: m.decides === true,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ type Model struct {
|
||||
// mode when the request says service_tier "priority" (m.fast: Cursor's
|
||||
// plugin from 0.2.2, for a model Cursor has a fast variant of)
|
||||
Fast bool `json:"fast"`
|
||||
// Decides is set by the plugin on a model that answers System One's
|
||||
// questions rather than a conversation (m.decides: a decision model
|
||||
// not named jev-…, Clef or a vendor's own). It counts only where the
|
||||
// provider says it serves a decision API (Provider.Decide).
|
||||
Decides bool `json:"decides,omitempty"`
|
||||
}
|
||||
|
||||
// Provider is a provider a plugin signs in to.
|
||||
@@ -92,7 +97,12 @@ type Provider struct {
|
||||
Usage bool `json:"usage"`
|
||||
// Checkin says the plugin presses its vendor's daily check-in for each
|
||||
// account (auth.checkin)
|
||||
Checkin bool `json:"checkin,omitempty"`
|
||||
Checkin bool `json:"checkin,omitempty"`
|
||||
// Decide says the plugin serves a decision API (TypeSafe's System
|
||||
// One) for this provider: its config hook set decide on it. magpie
|
||||
// posts the questions to the provider's own base, at /systemone,
|
||||
// through the plugin's fetch (#1514).
|
||||
Decide bool `json:"decide,omitempty"`
|
||||
SignedIn bool `json:"signedIn"`
|
||||
AuthType string `json:"authType"`
|
||||
AccountID string `json:"accountId"`
|
||||
|
||||
+12
@@ -87,6 +87,15 @@ export const FakePlugin = async ({ client }) => ({
|
||||
if (process.env.FAKE_GROK) cfg.provider[ID].models["grok-4.7"] = { name: "Grok 4.7", provider: { npm: "@ai-sdk/openai" }, limit: { context: 4000, output: 400 } }
|
||||
// $FAKE_DEEPSEEK: a DeepSeek model, as Cline's cline-pass/deepseek-v4-pro
|
||||
if (process.env.FAKE_DEEPSEEK) cfg.provider[ID].models["deepseek-v4-pro"] = { name: "DeepSeek V4 Pro", limit: { context: 1000, output: 100 } }
|
||||
// $FAKE_DECIDE: the provider serves a decision API too (#1514), asked
|
||||
// at its base /systemone through the loader's fetch: fake-clef is a
|
||||
// decision model it marks, jev-9 one magpie knows by its name.
|
||||
// "models" marks them without saying decide.
|
||||
if (process.env.FAKE_DECIDE) {
|
||||
if (process.env.FAKE_DECIDE !== "models") cfg.provider[ID].decide = true
|
||||
cfg.provider[ID].models["fake-clef"] = { name: "Fake Clef", decides: true, limit: { context: 1000, output: 0 } }
|
||||
cfg.provider[ID].models["jev-9"] = { name: "Jev 9", limit: { context: 1000, output: 0 } }
|
||||
}
|
||||
// $FAKE_OFF: a model that stops thinking at none and one that can't,
|
||||
// as Factory's plugin has Kimi K3 and GLM-5.3 (#899)
|
||||
if (process.env.FAKE_OFF) {
|
||||
@@ -229,6 +238,9 @@ export const FakePlugin = async ({ client }) => ({
|
||||
if (p.models["fake-claude"]) Object.assign(p.models["fake-claude"], { rate: 0.5, rateWas: 1 })
|
||||
if (p.models["fake-gemini"]) p.models["fake-gemini"].rate = "x0.03"
|
||||
if (auth?.key === "few") return { "fake-1": p.models["fake-1"] }
|
||||
// $FAKE_DECIDE: one more decision model, marked on the list the hook
|
||||
// gives, as a plugin that reads its vendor's list marks one
|
||||
if (process.env.FAKE_DECIDE) p.models["fake-judge"] = { ...p.models["fake-1"], id: "fake-judge", name: "Fake Judge", api: { ...p.models["fake-1"].api, id: "fake-judge" }, free: false, decides: true }
|
||||
// $FAKE_FAST=tier: as Cursor's plugin 0.2.x lists a model, once per
|
||||
// context size, and from 0.2.2 says fast on the sizes Cursor has a
|
||||
// fast variant at (Opus 5.5's 300k, not its 1m); no -fast model
|
||||
|
||||
@@ -79,11 +79,15 @@ func (p Provider) DecideOnly() bool {
|
||||
}
|
||||
|
||||
// DecidesModel distinguishes Jev from the conversation models a gateway
|
||||
// also serves. A dedicated decision API may use any model name.
|
||||
// also serves. A dedicated decision API may use any model name, and a
|
||||
// plugin's are the ones it marks besides Jev's (#1514).
|
||||
func (p Provider) DecidesModel(model string) bool {
|
||||
if !p.Decides() {
|
||||
return false
|
||||
}
|
||||
if p.IsPlugin() {
|
||||
return p.pluginMarks(model) || jevID(model)
|
||||
}
|
||||
if p.DecideOnly() {
|
||||
return true
|
||||
}
|
||||
@@ -103,9 +107,35 @@ func (p Provider) isDecision(m catalog.Model) bool {
|
||||
if p.IsRemoteMagpie() {
|
||||
return m.Decides
|
||||
}
|
||||
if p.IsPlugin() && p.Decides() && m.Decides {
|
||||
return true
|
||||
}
|
||||
return p.DecidesModel(m.ID)
|
||||
}
|
||||
|
||||
// pluginMarks reports whether p's plugin marks model as a decision model
|
||||
// (plugin.Model.Decides), as it last listed its models.
|
||||
func (p Provider) pluginMarks(model string) bool {
|
||||
pp := *p.Account.plugin
|
||||
if cur, ok := PluginOf(p.ID); ok {
|
||||
pp = cur
|
||||
}
|
||||
m, ok := pluginModel(pp, model)
|
||||
return ok && m.Decides
|
||||
}
|
||||
|
||||
// pluginDecisions are the decision models a plugin's account lists, in
|
||||
// its order: the ones it marks, and Jev's by name.
|
||||
func (p Provider) pluginDecisions() []catalog.Model {
|
||||
var out []catalog.Model
|
||||
for _, m := range p.available() {
|
||||
if p.isDecision(m) {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// OpenRouter lists its decision models apart from its chat models (ARNO
|
||||
// on Discord): its /models has the chat ones alone, Jev Router among them
|
||||
// (typesafe/jev-router, a chat model that picks one), and
|
||||
@@ -129,8 +159,14 @@ func decisionsID(id string) string { return id + ".decisions" }
|
||||
|
||||
// DecisionModels are the decision models listed separately from a provider's
|
||||
// conversations: OpenRouter's own list, a Bailian Token Plan's decision
|
||||
// model, or a remote magpie's marked models.
|
||||
// model, or a remote magpie's or a plugin's marked models.
|
||||
func (p Provider) DecisionModels() []catalog.Model {
|
||||
if p.IsPlugin() {
|
||||
if !p.Decides() {
|
||||
return nil
|
||||
}
|
||||
return p.decideModels()
|
||||
}
|
||||
if !p.IsRemoteMagpie() && (p.DecideOnly() || !p.listsDecisions() && !p.bailianApart()) {
|
||||
return nil
|
||||
}
|
||||
@@ -221,7 +257,7 @@ func (p Provider) DecideVia() string {
|
||||
// Jev is the model a decision provider is asked with when the user picked
|
||||
// none: TypeSafe's latest stable one, or the one Jev a gateway serves.
|
||||
func (p Provider) Jev() string {
|
||||
if p.IsRemoteMagpie() {
|
||||
if p.IsRemoteMagpie() || p.IsPlugin() {
|
||||
if models := p.decideListed(); len(models) > 0 {
|
||||
return models[0].ID
|
||||
}
|
||||
@@ -330,6 +366,10 @@ func (p Provider) decideListed() []catalog.Model {
|
||||
if p.bailianApart() {
|
||||
return p.ownDecideModels()
|
||||
}
|
||||
if p.IsPlugin() {
|
||||
// the plugin's list is the account's, never a guessed Jev alias
|
||||
return p.pluginDecisions()
|
||||
}
|
||||
if p.listsDecisions() && !p.DecideOnly() {
|
||||
if live, _, ok := catalog.Live(decisionsID(p.ID)); ok && len(live) > 0 {
|
||||
return live
|
||||
@@ -494,7 +534,7 @@ func Deciders() []Entry {
|
||||
continue
|
||||
}
|
||||
ms := p.Exposed()
|
||||
if !p.DecideOnly() && (len(p.Models) == 0 || p.listsDecisions() || p.bailianApart() || p.IsRemoteMagpie()) {
|
||||
if !p.DecideOnly() && (len(p.Models) == 0 || p.listsDecisions() || p.bailianApart() || p.IsRemoteMagpie() || p.IsPlugin()) {
|
||||
ms = p.decideModels() // the conversation picker's limit does not hide Jev
|
||||
}
|
||||
for _, m := range ms {
|
||||
@@ -683,6 +723,19 @@ func (p Provider) fetchDecide(ctx context.Context) ([]catalog.Model, error) {
|
||||
}
|
||||
return p.decideModels(), nil
|
||||
}
|
||||
if p.IsPlugin() {
|
||||
// a plugin lists its decision models with its others and answers
|
||||
// no list of its own at the decision base: the first is asked the
|
||||
// smallest question, through its fetch, which is what checks it
|
||||
ms := p.decideModels()
|
||||
if len(ms) == 0 {
|
||||
return nil, fmt.Errorf("%s's plugin lists no decision models", p.Name)
|
||||
}
|
||||
if err := p.AskSystemOne(ctx, ms[0].ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ms, nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
|
||||
defer cancel()
|
||||
switch p.DecideVia() {
|
||||
@@ -797,7 +850,8 @@ func (p Provider) AskSystemOne(ctx context.Context, model string) error {
|
||||
if err := p.Sign(ctx, req, Chat, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
// a plugin's goes through its fetch (Do), at plugin://<id>/v1/systemone
|
||||
res, err := p.Do(http.DefaultClient, req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %v", p.Name, err)
|
||||
}
|
||||
|
||||
@@ -172,6 +172,9 @@ func pluginCatalog(pp plugin.Provider) []catalog.Model {
|
||||
APIs: []string{string(pluginProtocol(pp.ID, m))}, Images: m.Image,
|
||||
Context: m.Input, Output: m.Output, Free: m.Free,
|
||||
Rate: m.Rate, RateWas: m.RateWas,
|
||||
// a decision model the plugin marked counts only where it
|
||||
// serves a decision API (pp.Decide)
|
||||
Decides: pp.Decide && m.Decides,
|
||||
}
|
||||
if c.Context == 0 {
|
||||
c.Context = m.Context
|
||||
@@ -343,6 +346,13 @@ func pluginProvider(pp plugin.Provider, l pluginLogin) Provider {
|
||||
a.codeAssist = pluginBase + pp.ID
|
||||
}
|
||||
}
|
||||
if pp.Decide {
|
||||
// its decision API is the provider's own base, asked at
|
||||
// /systemone through the plugin's fetch: pluginFetch sends nowhere
|
||||
// but the loader's host, so an address of the plugin's own
|
||||
// couldn't be reached (#1514)
|
||||
p.Decide = pluginBase + pp.ID + "/v1"
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
@@ -286,6 +286,10 @@ magpie quota <span class="c"># acme · Pro · 5h 37%
|
||||
</div>
|
||||
<p>モデルには、プロバイダとは別の API やアドレスを使うための <code>provider: { npm, api }</code>、<code>headers</code>、<code>options</code>、そして非表示にするための <code>disabled: true</code> も指定できます。</p>
|
||||
|
||||
<h3 id="decide">判定 API(System One)</h3>
|
||||
<p>プラグインは自分のプロバイダ向けに TypeSafe の System One API を提供でき、そのモデルを<a href="/docs/ja/intent">ルーティンググループの分類器</a>にできます。<code>config</code> フックでプロバイダに <code>decide: true</code> を、会話ではなく質問に答えるモデルごとに <code>decides: true</code> を設定します(<code>config</code> フックでも <code>models</code> フックのリストでも構いません)。すると magpie は各質問を <code>POST {baseURL}/systemone</code> としてローダーの <code>fetch</code> に送ります。アカウントのサインイン情報は他のリクエストと同じく付きます。本文は <code>{"model", "questions", "state"}</code>、返答は <code>{"model", "answers": {"<質問>": {"choice", "score", "confidence"}}}</code> です。</p>
|
||||
<p><code>decides</code> を付けたモデルと <code>jev-*</code> という名前のモデルは分類器として提示され、エージェントには見せません。それらへのチャットリクエストは拒否されます。プロバイダに <code>decide: true</code> がなければ <code>decides</code> は無視され、どのモデルも普通にチャットに使えます。</p>
|
||||
|
||||
<h3 id="apis">モデルが話す API</h3>
|
||||
<p>モデルまたはプロバイダの <code>npm</code> で指定した AI SDK パッケージが API を決めます。それによって、あなたの <code>fetch</code> が受け取るリクエストの形が決まります。エージェントが何を送ってきても、magpie のゲートウェイがすでに変換済みです:</p>
|
||||
<div class="table-wrap"><table>
|
||||
|
||||
@@ -286,6 +286,10 @@ magpie quota <span class="c"># acme · Pro · 5h 37%
|
||||
</div>
|
||||
<p>A model can also say <code>provider: { npm, api }</code> to use another API or address than the provider’s, <code>headers</code>, <code>options</code>, and <code>disabled: true</code> to hide it.</p>
|
||||
|
||||
<h3 id="decide">A decision API (System One)</h3>
|
||||
<p>A plugin can serve TypeSafe’s System One API for its provider, so its models can be a <a href="/docs/intent">routing group’s classifier</a>. Set <code>decide: true</code> on the provider in the <code>config</code> hook, and <code>decides: true</code> on each model that answers questions rather than a conversation, in the <code>config</code> hook or on the <code>models</code> hook’s list. magpie then posts each question as <code>POST {baseURL}/systemone</code> through your loader’s <code>fetch</code>, with the account’s sign-in, as it sends any other request. The body is <code>{"model", "questions", "state"}</code>; answer <code>{"model", "answers": {"<question>": {"choice", "score", "confidence"}}}</code>.</p>
|
||||
<p>A marked model, and one named <code>jev-*</code>, is offered as a classifier and kept from agents: a chat request to it is refused. Without <code>decide: true</code> on the provider, <code>decides</code> is ignored and every model stays one to chat with.</p>
|
||||
|
||||
<h3 id="apis">The API a model speaks</h3>
|
||||
<p>The AI SDK package named by <code>npm</code>, on the model or on the provider, decides the API. That decides the shape of the request your <code>fetch</code> receives. Whatever the agent sent, magpie’s gateway has already translated it:</p>
|
||||
<div class="table-wrap"><table>
|
||||
|
||||
@@ -286,6 +286,10 @@ magpie quota <span class="c"># acme · Pro · 5h 37%
|
||||
</div>
|
||||
<p>模型还可以写 <code>provider: { npm, api }</code>,使用和供应商不同的 API 或地址;也可以写 <code>headers</code>、<code>options</code>,以及用 <code>disabled: true</code> 隐藏它。</p>
|
||||
|
||||
<h3 id="decide">决策 API(System One)</h3>
|
||||
<p>插件可以为自己的提供商提供 TypeSafe 的 System One API,这样它的模型就能当<a href="/docs/zh/intent">路由组的分类器</a>。在 <code>config</code> 钩子里给提供商设 <code>decide: true</code>,并给每个只回答问题、不用来对话的模型设 <code>decides: true</code>(写在 <code>config</code> 钩子里或 <code>models</code> 钩子的列表上都行)。之后 magpie 会把每个问题以 <code>POST {baseURL}/systemone</code> 发给 loader 的 <code>fetch</code>,带上账号的登录信息,和其他请求一样。请求体是 <code>{"model", "questions", "state"}</code>;回答 <code>{"model", "answers": {"<问题>": {"choice", "score", "confidence"}}}</code>。</p>
|
||||
<p>标了 <code>decides</code> 的模型,以及名为 <code>jev-*</code> 的模型,会作为分类器提供,并对智能体隐藏:发给它的对话请求会被拒绝。提供商没有 <code>decide: true</code> 时,<code>decides</code> 不起作用,所有模型照常用于对话。</p>
|
||||
|
||||
<h3 id="apis">模型使用的 API</h3>
|
||||
<p>模型或供应商上 <code>npm</code> 指定的 AI SDK 包决定了 API,也就决定了你的 <code>fetch</code> 收到的请求格式。无论 agent 发来的是什么,magpie 的网关都已经转换好了:</p>
|
||||
<div class="table-wrap"><table>
|
||||
|
||||
Reference in New Issue
Block a user