The groups plugin now owns the user's own routing groups at the router strategy point. The groups magpie finds (auto-<model>, one model several providers serve) stay core, as Smart does: a new install has groups off under Essentials, and taking those would silently drop cross-provider failover. planGroup and the walk over a group's members stay core too. - provider.GateGroups / ServeGroups (group_serve.go): the gateway holds the gate while it serves; the plugin holds ServeGroups while on. Gated with none served, groupsIn drops every group not Auto, so FindGroup, GroupFor, the catalog and /v1/models go without them. The CLI and TUI are never gated. Nothing derived from groups is cached past a call, so a flip is seen by the next lookup. - Gated and off, a lookup that finds a user group asks the gate's refresh (pluginrt.Refresh in the gateway) at most once a second, never re-entrantly, then looks again. Without this, `magpie group add` was 404 for up to 2s until KeepFresh turned the plugin on (seen in the sandbox). - plugins/groups and plugins/routing: InUse is provider.NamedGroups, the file's non-Auto, non-hidden groups read past the gate; an unreadable providers.json is an error, so the plugin stays on. Run before rebasing onto707fbb249: - go test -count=1 -timeout 40m ./... : all ok (59 packages) - gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: clean - sandbox, real nogui binary + `magpie serve` + two fake upstreams: before add: group/auto-m listed, group/mine 404; right after `magpie group add Mine models=pa/x,pb/m`: group/mine listed and 200; after `group rm`: 404, auto-m still served. After the rebase onto707fbb249: vets (3 OSes) and go test of internal/provider, internal/gateway, internal/pluginrt and plugins/... all ok. Broken by hand, each went red: - groupsIn filter removed: TestOwnGroupsWaitOnThePlugin, TestGroupsOnAndOff/off - NamedGroups swallowing the read error: TestNamedGroupsUnreadable, plugins/groups TestInUse - Apply not serving: TestOnServesOffDoesNot - refresh not called / not throttled / asked for Auto groups too: TestOwnGroupRefreshesTheGate
31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
// Package groups is routing groups: several models agents pick as one,
|
|
// each request sent to the right one and on to the next when one fails.
|
|
// While the user has a group, it stays on.
|
|
//
|
|
// It serves the user's own groups on the gateway's router strategy point
|
|
// (P3 of docs/subsystems/plugin-runtime.md): Apply holds
|
|
// provider.ServeGroups, and off, the gateway neither lists nor routes them.
|
|
// The groups magpie finds (one model several providers serve) are the
|
|
// core's, on or off.
|
|
package groups
|
|
|
|
import (
|
|
"github.com/yetone/magpie/internal/pluginrt"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
func init() {
|
|
pluginrt.Register(pluginrt.Manifest{
|
|
ID: "groups", API: "^1", Requires: []string{"window", "providers"},
|
|
Name: "Routing groups", Sub: "Several models agents pick as one: each request goes to the right one, and to the next when one fails",
|
|
One: "1 group in use", Many: "{n} groups in use",
|
|
// a providers.json that can't be read is not known, so it stays on
|
|
InUse: provider.NamedGroups,
|
|
Parts: []pluginrt.Part{{Slot: "part", Key: "groups"}},
|
|
Apply: func(c *pluginrt.Ctx) error {
|
|
c.OnDispose(provider.ServeGroups())
|
|
return nil
|
|
},
|
|
})
|
|
}
|