What changed: the plugin host carries a model's temperature where it is said - the config model's temperature (Factory 0.1.31's configModels, plugins#154), models.dev's own, or a models hook's model field - into plugin.Model and pluginCatalog's catalog model, where RejectsTemperature reads it as it reads a built-in's. A Chat or Responses request relayed as it came to a model whose list refuses temperature and top_p now leaves them out (passthrough), as the translation of one (build) already did. A model nothing says so of keeps what the client sent. OpenCode's capabilities.temperature is not read: its false is what it reads a models.dev silence as, not a refusal said. Docs: the sampling row of gateway-routing, and provider-plugins' new "A plugin model's sampling". Run atea3dee96+ this change, sandbox HOME: go test -tags nogui -p 2 -run TestPluginModelRefusingTemperature ./internal/gateway/ - red atea3dee96without this change (the plugin's fetch got temperature 0.7, top_p 0.9 relayed, temperature 0.7 translated; the model that says nothing keeps them), green with it; ablation removed the four product files and went red the same way. go test -tags nogui -p 2 -timeout 45m ./internal/gateway/ ok (291s); go test -tags nogui -p 2 ./internal/plugin/ ok; -run 'TestRejectsTemperature|TestPluginModel|TestPluginCatalog|PluginParity|TestPlugin' ./internal/provider/ ok; -run 'TestSampling|TestUpstreamBytes|TestPassthrough|TestRelay' ./internal/gateway/ ok. gofmt -l internal/ clean; go vet ./... (darwin, the trayimage_darwin.go cgo warning as before), GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... clean; go build and GOOS=linux/windows go build ok. Landed (yetone). Broken by hand on mote: with gateway.go, host.js, internal/plugin/providers.go and internal/provider/plugins.go at origin/main, TestPluginModelRefusingTemperature is red. passthrough strips temperature and top_p for a provider whose catalog says temperature false on Chat and Responses alike, the same rule build applies. Run at the pushed head: go test ./... -timeout 45m on mote with this branch on41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at41b5c0f19too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at41b5c0f19and here. Rebased onf856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased onbb478f0e5: agent and gateway ok, gui the same. The last rebase, onto573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch. Generated-by: GLM-5.3-Flash (ZCode)
82 lines
3.3 KiB
Go
82 lines
3.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// A plugin model whose config says temperature: false — as factory 0.1.31's
|
|
// config models say it of its OpenAI route (plugins#154, sweanng424: the
|
|
// vendor turned temperature and top_p away with a 400) — is asked without
|
|
// them, however the client speaks: relayed as it came, or translated. One
|
|
// that says nothing of it keeps what the client sent (#2492).
|
|
func TestPluginModelRefusingTemperature(t *testing.T) {
|
|
t.Setenv("FAKE_TEMP", "1")
|
|
var mu sync.Mutex
|
|
var seen []map[string]any
|
|
pid := besideFake(t, "opencode-zen-free", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
b, _ := io.ReadAll(r.Body)
|
|
var q map[string]any
|
|
json.Unmarshal(b, &q)
|
|
mu.Lock()
|
|
seen = append(seen, q)
|
|
mu.Unlock()
|
|
w.Header().Set("Content-Type", "text/event-stream")
|
|
b1, _ := json.Marshal(map[string]any{"id": "c1", "object": "chat.completion.chunk", "choices": []any{map[string]any{"index": 0, "delta": map[string]any{"content": "ok"}, "finish_reason": nil}}})
|
|
io.WriteString(w, "data: "+string(b1)+"\n\n")
|
|
io.WriteString(w, `data: {"id":"c1","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}`+"\n\ndata: [DONE]\n\n")
|
|
}))
|
|
h := New().Handler()
|
|
ask := func(path, body string) (int, string) {
|
|
req := httptest.NewRequest("POST", path, strings.NewReader(body))
|
|
req.Header.Set("Authorization", "Bearer magpie")
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, req)
|
|
return rec.Code, rec.Body.String()
|
|
}
|
|
last := func() map[string]any {
|
|
t.Helper()
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if len(seen) == 0 {
|
|
t.Fatal("the plugin's fetch was never asked")
|
|
}
|
|
return seen[len(seen)-1]
|
|
}
|
|
has := func(q map[string]any, field string) bool {
|
|
_, ok := q[field]
|
|
return ok
|
|
}
|
|
// relayed as it came: a streamed chat request goes through as the
|
|
// client sent it, temperature and all, the model's name swapped
|
|
code, body := ask("/v1/chat/completions", `{"model":"`+pid+`/fake-cold","stream":true,"temperature":0.7,"top_p":0.9,"messages":[{"role":"user","content":"hi"}]}`)
|
|
if code != 200 {
|
|
t.Fatalf("fake-cold relayed: %d %s", code, body)
|
|
}
|
|
if q := last(); has(q, "temperature") || has(q, "top_p") {
|
|
t.Errorf("the plugin's fetch got a model that refuses them asked with temperature %v, top_p %v", q["temperature"], q["top_p"])
|
|
}
|
|
// translated from Claude's API, which has no model list of its own to
|
|
// read the refusal from: the built chat request carries neither
|
|
code, body = ask("/v1/messages", `{"model":"`+pid+`/fake-cold","max_tokens":100,"temperature":0.7,"messages":[{"role":"user","content":"hi"}]}`)
|
|
if code != 200 {
|
|
t.Fatalf("fake-cold translated: %d %s", code, body)
|
|
}
|
|
if q := last(); has(q, "temperature") {
|
|
t.Errorf("the translated request asked temperature %v of a model that refuses it", q["temperature"])
|
|
}
|
|
// one that says nothing keeps what the client sent
|
|
code, body = ask("/v1/chat/completions", `{"model":"`+pid+`/fake-1","stream":true,"temperature":0.7,"top_p":0.9,"messages":[{"role":"user","content":"hi"}]}`)
|
|
if code != 200 {
|
|
t.Fatalf("fake-1 relayed: %d %s", code, body)
|
|
}
|
|
if q := last(); !has(q, "temperature") || !has(q, "top_p") {
|
|
t.Errorf("a model that says nothing of temperature was asked without it (temperature %v, top_p %v)", q["temperature"], q["top_p"])
|
|
}
|
|
}
|