Files
magpie/internal/provider/mlxserve_decide.go
T
yetone 68d1fda92b providers: GPUStack, a self-hosted model server, in the Add sheet (tayedexuanfeng on X)
tayedexuanfeng asked for GPUStack so locally deployed models import quickly.
GPUStack (github.com/gpustack/gpustack, read at 26b4af6) serves its
OpenAI-compatible API at <server>/v1 (/v1-openai is the legacy path), takes
the key as a Bearer (docs/user-guide/api-key-management.md), and lists the
ready models at GET /v1/models as {"object":"list","data":[{"id",
"object":"model","created","owned_by":"gpustack"}]} (routes/openai.py).

A KindLocal preset, so the Add sheet's Server address field, the CLI's
address=, the TUI's ask and AtAddress all apply as for Ollama; unlike
Ollama it is not NoKey, so its key is asked for. Default http://localhost/v1
(port 80). Logo: the project's own docs/assets/logo.png (Apache-2.0), 96px,
in pngIcons as mlx-serve's is (lobehub has none). Note translated in zh,
zh-TW, ja, de.

Run on mote: go test -count=1 of internal/provider, gui, cli, tui (ok);
go vet on darwin, windows and linux nogui for provider and gui (ok);
GUI i18n-keys, i18n-en-no-cjk, models-add-and-icons, local-address and the
new gpustack-add (56 of 56 in chromium and webkit; gpustack-add also in en,
zh, zh-TW, ja, de at 900 and 440px). The new Go tests use a fake server in
GPUStack's documented shape and never reach the network.
Broken by hand: NoKey true on the preset turns TestGPUStackPreset red;
dropping gpustack from pngIcons turns gpustack-add red (11 failed).
Not tried: a real GPUStack server (none on the LAN), the Linux WebKitGTK
app, the Windows box. Not built: GPUStack's /v1/responses and /v1/messages
(chat only).
2026-11-11 08:31:55 +08:00

82 lines
2.4 KiB
Go

package provider
import (
"encoding/json"
"fmt"
"slices"
"strings"
"github.com/yetone/magpie/internal/catalog"
)
// MLXServePreset is the MLX-Serve preset's id.
const MLXServePreset = "mlx-serve"
// GPUStackPreset is GPUStack's preset id.
const GPUStackPreset = "gpustack"
// MLX-Serve (github.com/ddalcu/mlx-serve) serves decision models —
// Clef, Clef-Flash, Kev, Laya, D1 — at POST /v1/systemone (and /v1/decisions),
// System One's questions and answers. Its /v1/models lists them alongside
// chat models, marking them with capabilities: ["decisions"]. That list
// is the provider's decision models, as oMLX's and OpenRouter's are
// (listsDecisions), and a model without that capability stays a chat model.
func (p Provider) mlxServeDecides() bool {
return p.Preset == MLXServePreset && p.Decide != "" && !p.DecideOnly()
}
// mlxServeDecisions is where MLX-Serve lists its models and capabilities.
func mlxServeDecisions(base string) string {
return strings.TrimRight(base, "/") + "/models"
}
type mlxServeModel struct {
ID string `json:"id"`
ContextLength int `json:"context_length"`
MaxModelLen int `json:"max_model_len"`
Capabilities []string `json:"capabilities"`
InputModalities []string `json:"input_modalities"`
}
// listedMLXServeDecide are the decision models in MLX-Serve's /v1/models:
// those whose capabilities include "decisions", with the window and input
// modalities MLX-Serve serves them with.
func listedMLXServeDecide(b []byte) ([]catalog.Model, error) {
var out struct {
Data *[]mlxServeModel `json:"data"`
Models *[]mlxServeModel `json:"models"`
}
if err := json.Unmarshal(b, &out); err != nil || (out.Data == nil && out.Models == nil) {
return nil, fmt.Errorf("not MLX-Serve's model list")
}
rows := out.Data
if rows == nil {
rows = out.Models
}
ms := []catalog.Model{}
for _, m := range *rows {
if m.ID == "" || !slices.Contains(m.Capabilities, "decisions") {
continue
}
ctx := m.MaxModelLen
if ctx <= 0 {
ctx = m.ContextLength
}
var imageInput *bool
images := false
if len(m.InputModalities) > 0 {
images = slices.Contains(m.InputModalities, "image")
imageInput = &images
}
ms = append(ms, catalog.Model{
ID: m.ID,
Name: m.ID,
Context: ctx,
ImageInput: imageInput,
Images: images,
InputModalities: m.InputModalities,
})
}
return ms, nil
}