kdajenks (magpie 0.1.3739, Codex on ChatGPT Pro) could set Fast only from a
routing group's member row and had no Ultrafast there, and no way to set the
speed in the model's own settings. Ultrafast exists: Codex's catalog lists
the `ultrafast` service tier, the code already sent it for agent picks and
Codex's service-tier row, and the live account's service_tiers hold it.
- Group member: the button steps Standard speed, Fast, Ultrafast (where an
account offers it, `ultraOK`), back to Standard. `Group.Ultra` is a subset of
`Fast`, kept through rename, fold, share, gone-filter and the CLI
(`magpie group ... ultra=`). The gateway marks the candidate `ultra`.
- Per model: `settings.ModelTiers` ("<provider>/<model>" to priority or
ultrafast), `provider.SetModelTier` (refused where CanFast/CanUltra say no),
`ModelPref.Tier` in Model settings (Standard speed / Fast / Ultrafast, in
modellimits.js), and `magpie model tier <provider/model> [fast|ultrafast|usual]`.
The gateway sends it on a direct pick for an agent with no fast pick of its
own, through fastPick, so an account without Ultrafast gets priority. A group
member goes as the group says.
- Docs: gateway-routing, providers-accounts, reference.
Run (mica, at the rebased head over a6d84e13a):
- gofmt -l clean; go vet darwin, linux nogui, windows clean.
- go test internal/provider, internal/settings ok; internal/gui and
internal/cli ran: the one red of mine (TestSettingsSaveKeepsWhatItDoesNotSend
wanting ModelTiers) is fixed in this commit; the others are not mine and
red on a clean origin/main: TestEveryRouteHasACommandOrIsNamed (#6202),
TestPanelHiddenByWailsMarksPageOutOfSight (#6203, not checked on main).
- internal/gateway ok (984s).
- GUI, chromium and webkit: new model-speed.test.cjs (30, five languages, 1200
and 420px), plus model-*, group-*, fast-*, i18n-*, text-size,
codex-service-tier, panel-*, routing-group*, routing-save* files. Red and not
mine, same on a clean origin/main worktree: fast-pick and fast-ultra (#6201),
group-editor-selected (#5049).
- New tests TestModelTierSentToEveryAgent, TestGroupMemberUltrafast,
TestCleanModelTier, TestSaveGroupUltra.
Broken by hand: removing the gateway's model-tier branch and the candidate
`ultra` copies turned both gateway tests red; turning off the Ultrafast choice
in Model settings turned 20 of 30 GUI tests red; reverting the member button to
two states turned 10 of 30 red.
Not tried: a real ChatGPT account sending Ultrafast through the new setting;
the agent picker's bolt does not show a model-level default; Windows and Linux
GUI runs.
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
package provider
|
|
|
|
// A model's own speed (kdajenks on X): the service tier the user gave one
|
|
// model in its Model settings, kept in settings' ModelTiers by "<provider
|
|
// id>/<model id>": "priority" (Codex's Fast) or "ultrafast" (its Ultra
|
|
// Fast, which a plan that doesn't offer it is sent priority in place of). The
|
|
// gateway sends every request for the model so, for each agent that has no
|
|
// pick of its own for it (an agent's fast pick, FastPicks, is that agent's
|
|
// and goes first). A routing group's member is sent as the group says.
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// ModelTier is the tier the user gave provider pid's model, "" for none. It
|
|
// reads the held settings, as it is asked on every request.
|
|
func ModelTier(pid, model string) string {
|
|
if pid == "" || model == "" {
|
|
return ""
|
|
}
|
|
return heldSettings().ModelTiers[pid+"/"+model]
|
|
}
|
|
|
|
// CleanModelTier reads the words people use for a tier: "" (also off,
|
|
// usual, standard) for none, "priority" (fast), "ultrafast" (ultra,
|
|
// ultra-fast).
|
|
func CleanModelTier(v string) (string, error) {
|
|
switch strings.ToLower(strings.TrimSpace(v)) {
|
|
case "", "off", "none", "usual", "standard", "default":
|
|
return "", nil
|
|
case "priority", "fast":
|
|
return "priority", nil
|
|
case "ultrafast", "ultra", "ultra-fast", "ultra_fast":
|
|
return "ultrafast", nil
|
|
}
|
|
return "", fmt.Errorf("a model's speed is one of usual, fast or ultrafast, not %q", v)
|
|
}
|
|
|
|
// SetModelTier sends a provider's model, spelt "provider/model", at tier:
|
|
// "" the usual speed, "priority" or "ultrafast" (see CleanModelTier). Only
|
|
// a model with a fast mode magpie can ask for (CanFast) is switched on.
|
|
func SetModelTier(ref, tier string) error {
|
|
_, err := setModelTier(ref, tier)
|
|
return err
|
|
}
|
|
|
|
func setModelTier(ref, tier string) (bool, error) {
|
|
p, model, err := splitRef(ref)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if tier, err = CleanModelTier(tier); err != nil {
|
|
return false, err
|
|
}
|
|
key := p.ID + "/" + model
|
|
if tier != "" {
|
|
if !CanFast(*p, model) {
|
|
return false, fmt.Errorf("%s has no fast mode magpie can ask for", key)
|
|
}
|
|
if tier == "ultrafast" && !CanUltra(*p, model) {
|
|
return false, fmt.Errorf("no account offers Ultrafast on %s", key)
|
|
}
|
|
}
|
|
s := settings.Load()
|
|
if s.ModelTiers[key] == tier {
|
|
return false, nil
|
|
}
|
|
if tier == "" {
|
|
delete(s.ModelTiers, key)
|
|
} else {
|
|
if s.ModelTiers == nil {
|
|
s.ModelTiers = map[string]string{}
|
|
}
|
|
s.ModelTiers[key] = tier
|
|
}
|
|
if err := settings.Save(s); err != nil {
|
|
return false, err
|
|
}
|
|
return true, nil
|
|
}
|