agent: Pi offers xhigh and max for models that have them

Pi shows xhigh and max only for models whose thinkingLevelMap names them,
and magpie wrote just "reasoning", so a model whose top level is max (GLM-5.3,
DeepSeek) stopped at high and a max setting was sent as high (#5). Checked on
the wire: --thinking max sent reasoning_effort high before, max after. Picking
the model or thinking level in magpie again rewrites Pi's models.json.
This commit is contained in:
yetone committed 2026-09-24 11:15:59 +08:00
1 parent 24f9edafa1
commit 1786bc3c3d
2 files changed
+44 -1

No files matched your search

+21 -1
View File
@@ -163,7 +163,11 @@ func magpieProviderJSON(shape string) any {
var ms []map[string]any
for _, m := range models {
// reasoning lets Pi offer its thinking levels for the model
ms = append(ms, map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0})
e := map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0}
if levels := piThinkingLevels(m.Efforts); levels != nil {
e["thinkingLevelMap"] = levels
}
ms = append(ms, e)
}
if ms == nil {
ms = []map[string]any{}
@@ -173,6 +177,22 @@ func magpieProviderJSON(shape string) any {
return nil
}
// piThinkingLevels is the thinkingLevelMap for a model's efforts. Pi offers
// xhigh and max only for models that map them, so without it a model whose
// top level is max stopped at high in Pi.
func piThinkingLevels(efforts []string) map[string]any {
var levels map[string]any
for _, e := range efforts {
if e == "xhigh" || e == "max" {
if levels == nil {
levels = map[string]any{}
}
levels[e] = e
}
}
return levels
}
func opencode(home, cfg string) *Agent {
dir := filepath.Join(cfg, "opencode")
path := filepath.Join(dir, "opencode.json")
+23
View File
@@ -0,0 +1,23 @@
package agent
import (
"reflect"
"testing"
)
func TestPiThinkingLevels(t *testing.T) {
for _, c := range []struct {
efforts []string
want map[string]any
}{
{[]string{"low", "high", "max"}, map[string]any{"max": "max"}},
{[]string{"low", "medium", "high", "xhigh"}, map[string]any{"xhigh": "xhigh"}},
{[]string{"none", "low", "high", "xhigh", "max"}, map[string]any{"xhigh": "xhigh", "max": "max"}},
{[]string{"low", "medium", "high"}, nil},
{nil, nil},
} {
if got := piThinkingLevels(c.efforts); !reflect.DeepEqual(got, c.want) {
t.Errorf("%v: got %v, want %v", c.efforts, got, c.want)
}
}
}