"classifier的模型调用可以加上不带思考的参数么?提速效果比较好". A routing
group's classifier (and its effort question) asked its model for the
least level on its list, and nothing at all when the list was unknown,
so a relay's reasoning model thought at its vendor's default before
answering a number.
Now classifyEffort asks for none, reasoning off, and each wire fits it
with the code that already fits a client's none:
- Chat/Responses: a model with none gets none; one without gets its
lowest (fitFor: low, minimal), as before; one whose levels aren't
known gets none (as auto mode's classifier does, fitAutoModeClassifier).
- Anthropic: thinking {"type":"disabled"}; Opus 5.5, which refuses it,
still has it left out (thinkingOffAsTaken).
- Gemini API / Code Assist 2.5: thinkingConfig.thinkingBudget is the
off budget (0 for Flash and Flash-Lite, 128 for Pro, as Vertex already
did) where a Chat none went as low's 4096. Gemini 3 is unchanged (low).
- A model the user marked as taking no reasoning ask (Reasonless) is
sent none at all; a routing group as classifier is left as before.
- An upstream that turns the effort away (unknown reasoning_effort
field, or the level) is asked again without it and remembered
(askLeast), so the classifier keeps answering.
The Image recognition model keeps its old least-level rule
(leastEffort); only the classifier changed.
Run (mote-run, this tree on origin/main 90518de26, rebased onto
d83823d26, which touches internal/agent only):
- go test ./internal/gateway -run 'TestClassifierAsksThinkingOff|
TestClassifierThinkingAsEachVendorTakes|TestVisionEffortUnchangedByClassifier|
TestIntent|Classif|TestAdaptiveOnly|Vertex|Gemini|Think|Decide|Effort': ok
- go test ./internal/gateway -run 'CodeAssist|Codeassist|Antigravity|
GeminiCLI|Gemini|AIStudio|Auto|Rule|Group|Vision|Search|Reason|Off': ok
- go vet ./internal/gateway on darwin, linux, windows; gofmt -l clean.
Broken by hand: classifyEffort back to the least level and the 2.5
off budget turned off: TestClassifierAsksThinkingOff (anthropic, gemini
2.5 flash, unknown chat), TestIntentClassifierEffort and the 2.5 Pro case
go red. Before askLeast, the "effort turned away" case was red (the
classifier failed on a relay refusing reasoning_effort).
Not tried: a real vendor account; the whole internal/gateway package
and full suite (running after the push). On Anthropic, the old body for
claude-sonnet-4-5 had no thinking at max_tokens 2048, so that model
wasn't thinking before either; the change there is the explicit
disabled.
120 lines
3.5 KiB
Go
120 lines
3.5 KiB
Go
package gateway
|
|
|
|
import (
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// The reasoning level picked in Settings for a model magpie asks on its
|
|
// own, beside the model in use: Image recognition's and the searcher's
|
|
// (MOMO on Discord, "外置模型能不能提供思考深度选项"). Only those calls
|
|
// are asked so; every other request goes as it did.
|
|
|
|
// ModelEfforts are the reasoning levels model ("<provider>/<model>") has,
|
|
// weakest first, for Settings to offer beside it; none for one whose
|
|
// levels aren't known, or a routing group.
|
|
func ModelEfforts(model string) []string {
|
|
p, m, ok := provider.Resolve(model)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return ByStrength(p.Efforts(m))
|
|
}
|
|
|
|
// sideEffort is want fitted to model's own levels: "" when none is
|
|
// wanted, or the model's levels aren't known, so nothing is sent that it
|
|
// might refuse.
|
|
func sideEffort(model, want string) string {
|
|
levels := ModelEfforts(model)
|
|
if want == "" || len(levels) == 0 {
|
|
return ""
|
|
}
|
|
return fitEffort(want, levels)
|
|
}
|
|
|
|
// visionEffort is the level the Image recognition model is asked to read
|
|
// an image at: the one picked in Settings, else magpie's own, the least
|
|
// it has (leastEffort), as a description is wanted quickly.
|
|
func visionEffort(model string) string {
|
|
if e := sideEffort(model, provider.HeldSettings().VisionEffort); e != "" {
|
|
return e
|
|
}
|
|
return leastEffort(model)
|
|
}
|
|
|
|
// leastEffort is the least reasoning model takes: none when it can go
|
|
// without, else its lowest level; "" when its levels aren't known, which
|
|
// leaves it to the vendor.
|
|
func leastEffort(model string) string {
|
|
p, m, ok := provider.Resolve(model)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
levels := p.Efforts(m)
|
|
if len(levels) == 0 {
|
|
return ""
|
|
}
|
|
return fitEffort("none", levels)
|
|
}
|
|
|
|
// VisionEffortNow is the level the Image recognition model in use is
|
|
// asked at when one is picked in Settings ("" when none is): the picked
|
|
// one fitted to the model's levels, for the row to show.
|
|
func VisionEffortNow() string {
|
|
m, ok := seer()
|
|
if !ok {
|
|
return ""
|
|
}
|
|
return sideEffort(m, provider.HeldSettings().VisionEffort)
|
|
}
|
|
|
|
// VisionEfforts are the levels of the model that describes images now.
|
|
func VisionEfforts() []string {
|
|
if m, ok := seer(); ok {
|
|
return ModelEfforts(m)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// searchEffort is the level the searcher's model, provider p's model, is
|
|
// asked to search at: the one picked in Settings fitted to its levels,
|
|
// or "" to send none.
|
|
func searchEffort(p provider.Provider, model string) string {
|
|
if model == "" {
|
|
return ""
|
|
}
|
|
return sideEffort(p.ID+"/"+model, settings.Load().SearcherEffort)
|
|
}
|
|
|
|
// SearchEffortNow is the level the searcher in use is asked at, when one
|
|
// is picked in Settings.
|
|
func SearchEffortNow() string {
|
|
if p, m, ok := searcher(); ok {
|
|
return searchEffort(p, m)
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// SearchEfforts are the levels of the model that searches now: none for
|
|
// a Kimi Code plan's search service, which has no model.
|
|
func SearchEfforts() []string {
|
|
if p, m, ok := searcher(); ok && m != "" {
|
|
return ModelEfforts(p.ID + "/" + m)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// replyRoom is the reply limit a side call asked to think at effort is
|
|
// sent with: its usual limit with room for the thinking above it, so a
|
|
// level picked higher doesn't spend the reply on thinking and leave no
|
|
// answer. The model's own limit still caps it (withMaxOutput).
|
|
func replyRoom(usual int, effort string) int {
|
|
switch effort {
|
|
case "", "none":
|
|
return usual
|
|
case "minimal":
|
|
return usual + 1024
|
|
}
|
|
return usual + budgetOf(effortOf(effort))
|
|
}
|