dengtongcai asked for a routing rule that picks both the model and the reasoning it is asked for (a quick question goes to a cheap model at low). A rule now has an output field, useEffort (low|medium|high|xhigh|max). When the rule matches, its member is asked for that effort. A member's own fixed effort still wins. Otherwise the rule beats the model's suffix, the turn's pick and the agent's pick. The existing effort condition is unchanged. - The value is fitted to the model's levels (max -> high on a model that tops out at high). A model with no Efforts is sent what the agent asked, untouched. Unset changes nothing. Failover members are not affected. - The trace records it: Rule.UseEffort and the try's RuleEffort (the second Try construction in the candidate loop was missing it). - Saving a group rejects an unknown value or one on a pause (cleanRules). The CLI takes use-effort=; the TUI and CLI lists show " at <effort>". - GUI: a chip after the rule's model, picked from the app menu (pickFrom, no native select), set/changed from the rule's menu. A pause clears it. Strings in zh, zh-TW, ja, de. - A Gemini-protocol client is left unchanged, as with every effort magpie sets. - Docs: docs/subsystems/gateway-routing.md; site docs intent and start (en, zh, ja). What was run, at d4c03a2c5 (rebased ond4a1b9baa) unless said: - gofmt -l: none. go vet ./... (darwin), GOOS=linux and GOOS=windows go vet -tags nogui ./...: clean. - go test -count=1 ./internal/gateway ./internal/provider ./internal/cli ./internal/tui: ok. - The full go test -timeout 45m ./... under pipefail, before the rebase at6f950653f: every package ok except internal/gui. There, 8 real-window darwin tests were killed at their deadlines with the load average at 150-300. Four passed on a rerun. TestMainWindowCorners, TestMainWindowRightToLeft, TestTrayCellClickReleasedPanel and TestCoveredWindowStaysUp fail the same way on a clean6f950653fcheckout (added to #1936). This change has no Go in internal/gui. - Broken by hand: ruleEffort returning "" turns the four gateway tests red (Chat member, intent rule, failover member, Anthropic member). Returning the raw value for a model with no levels turns the unset/no-levels test red. Dropping the cleanRules checks turns TestCleanRulesUseEffort red. routing-rule-effort.test.cjs against the6f950653frouting client.js and i18n.js is red. - GUI: routing-rule-effort.test.cjs passes 18/18 in chromium and webkit (en, zh, zh-TW, ja, de; 1100 and 420 wide). The 140 GUI files that open the Routing view ran 560 tests before the run stopped with no summary. Two of the 560 were red: group-from-model-add (#2388) and name-suffix-where-named (filed #2640, a skeleton-row race). Both pass alone. The whole 791-file suite was not finished. At a load near 280 it covered about 20 files in 40 minutes. The reds it showed were in account-* files, and account-models passes 12/12 alone. - Then rebased onto8bb9375e7(#2635, internal/library only) and go build ./... at the final head.
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// #2633: a rule's useEffort is one of Efforts, saved lowercased; anything
|
|
// else is refused when the group is saved, and a pause takes none.
|
|
func TestCleanRulesUseEffort(t *testing.T) {
|
|
members := []string{"a/m", "b/big"}
|
|
got, err := cleanRules([]Rule{{Use: "a/m", Tokens: 10, UseEffort: " LOW "}, {Use: "b/big", Images: true}}, members)
|
|
if err != nil || got[0].UseEffort != "low" || got[1].UseEffort != "" {
|
|
t.Fatalf("%+v %v", got, err)
|
|
}
|
|
b, _ := json.Marshal(got)
|
|
if !strings.Contains(string(b), `"useEffort":"low"`) || strings.Count(string(b), "useEffort") != 1 {
|
|
t.Fatal(string(b))
|
|
}
|
|
for _, tc := range []struct {
|
|
rule Rule
|
|
err string
|
|
}{
|
|
{Rule{Use: "a/m", Tokens: 10, UseEffort: "huge"}, "one of low, medium, high, xhigh, max"},
|
|
{Rule{Use: "a/m", Tokens: 10, UseEffort: "on"}, "not \"on\""},
|
|
{Rule{Use: "a/m", Tokens: 10, UseEffort: "minimal"}, "not \"minimal\""},
|
|
{Rule{Use: "a/m", Pause: true, Agents: []string{"codex"}, UseEffort: "low"}, "a pause sends nothing"},
|
|
} {
|
|
if _, err := cleanRules([]Rule{tc.rule}, members); err == nil || !strings.Contains(err.Error(), tc.err) {
|
|
t.Errorf("%+v: %v, want …%s", tc.rule, err, tc.err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Typed: use-effort=<level>, read back the same; a bad level or a pause
|
|
// with one is refused.
|
|
func TestParseRuleUseEffort(t *testing.T) {
|
|
g := Group{ID: "g", Members: []string{"zhipu/glm-5.3", "kimi/k3"}, Classifier: "zhipu/glm-5.3"}
|
|
r, _, _, err := ParseRule(g, RuleWords(`use=k3 use-effort=High intent="simple questions"`))
|
|
if err != nil || r.Use != "kimi/k3" || r.UseEffort != "high" {
|
|
t.Fatalf("%+v %v", r, err)
|
|
}
|
|
if got := r.Line(); got != `use=kimi/k3 use-effort=high intent="simple questions"` {
|
|
t.Fatal(got)
|
|
}
|
|
again, _, _, err := ParseRule(g, RuleWords(r.Line()))
|
|
if err != nil || again.UseEffort != "high" {
|
|
t.Fatalf("%+v %v", again, err)
|
|
}
|
|
for _, bad := range []string{"use=k3 use-effort=huge tokens=1k", "use=k3 use-effort=on tokens=1k", "pause=k3 use-effort=low time=09:00-10:00"} {
|
|
if _, _, _, err := ParseRule(g, RuleWords(bad)); err == nil {
|
|
t.Errorf("%s parsed", bad)
|
|
}
|
|
}
|
|
}
|