Files
magpie/internal/gateway/muse.go
T
yetone 4547dafe95 models: Provider in model names has a third way, a name the user gave used just as they wrote it (#92 marsxxl: v0.1.591 的 Codex 下拉里自定义名称又带上了 · WorkBuddy / · Claude Code) — 559ce021 (#203) had a custom name keep " · <provider>" after it like any other, so "Opus 5.5" read "Opus 5.5 · Claude Code" in every list Labels feeds (Codex's model_catalog_json and the gateway's Codex /models, Pi's, OpenCode's, ZCode's, OMP's, Muse's), while #92 had been promised the name as written. Both are kept: the setting is now Off / Not on names I set (自定义名称不带供应商) / On. On stays the default and keeps #203's behaviour, so nobody's list changes unasked; own leaves a name the user gave as it is and a vendor's name with its provider's; off is #335's plain names. Stored as plainOwnNames beside plainNames, so a settings.json of before reads as it did (plainNames: true is off). POST /api/settings/plain-names takes mode on|own|off (a body of on alone still works), magpie model suffix on|own|off, a Settings save keeps it, and /v1/models' magpie_label now follows the setting through Labels as the agents' lists do. The row's hint is one line that fits (en, zh), and its zh name says 供应商 as the rest of the app. Prompts and headers are unchanged. TestSuffixMode, TestSuffixModesReachAgentFiles (Codex model_catalog_json and Pi models.json), TestModelsListSuffixModes (/v1/models magpie_label) and model-suffix-own.test.cjs (Chromium and WebKit, en and zh) fail without the change; TestModelName and TestModelNameAndLevelsReachAgentFiles keep #203's assertions. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestConfiguredModelsAdvertiseImageInput load-flaky, passes alone); plain-names, click-scroll, old-webkit pass.
2026-10-01 23:20:57 +08:00

52 lines
2.0 KiB
Go

package gateway
import (
"cmp"
"net/http"
"github.com/yetone/magpie/internal/provider"
)
// museContext and museOutput are what Muse is told of a model whose window
// or reply size magpie doesn't know.
const (
museContext = 128000
museOutput = 32000
)
// museModels serves Muse Code its model list. Muse asks for it at
// /muse-code/models on its endpoint's host, whatever path the endpoint has,
// before every session, and starts none when it isn't there, whatever model
// it is told to use; a model it lists is one whose metadata["muse-code"]
// says how Muse is to treat it (a row without it is one Muse hides, and a
// list of none it refuses). The ids are the catalog's, which Muse sends back
// as the model it asks /v1/responses for.
func (s *Server) museModels(w http.ResponseWriter, r *http.Request) {
shown := catalogFor(r)
labels := provider.Labels(shown)
data := []map[string]any{}
for i, e := range shown {
input := []string{"text"}
if e.Images {
input = append(input, "image")
}
meta := map[string]any{"name": labels[i], "family": e.Provider.ID, "is_hidden": false,
"attachment": e.Images, "reasoning": len(e.Efforts) > 0, "temperature": false, "tool_call": true,
"modalities": map[string]any{"input": input, "output": []string{"text"}},
"options": map[string]any{"include": []string{}}, "variants": map[string]any{},
"description": labels[i] + " via magpie"}
// the window and the most a reply may hold: Muse hides a model
// whose limit lacks either, and without a limit asks for replies
// of 128K tokens, more than most models give; one magpie doesn't
// know is told 128K and Muse's own 32K
ctx, out := cmp.Or(e.Context, museContext), e.Output
if out <= 0 {
out = min(museOutput, ctx)
}
meta["limit"] = map[string]any{"context": ctx, "output": out}
data = append(data, map[string]any{"id": e.ID, "object": "model", "created": 0, "owned_by": e.Provider.ID,
"metadata": map[string]any{"muse-code": meta}})
}
writeJSON(w, 200, map[string]any{"object": "list", "data": data})
}