Files
magpie/internal/provider/mlxserve_decide.go
T
Versun b2b015c584 provider: MLX-Serve's decision models classify routing groups through System One, separated from chat models by capabilities
MLX-Serve (github.com/ddalcu/mlx-serve) serves decision models (Clef,
Clef-Flash, Kev, Laya, D1) at POST /v1/systemone (and /v1/decisions). Its
/v1/models lists them alongside chat models, marking them with
capabilities: ["decisions"]. Setting a routing group classifier to an
mlx-serve decision model previously failed because the preset had no
decision endpoint and magpie offered it as a chat model, which MLX-Serve
rejected with 400.

- The mlx-serve preset has a decision base, http://localhost:11234/v1.
  An existing MLX-Serve provider saved without decide gets its chat base as
  one, at whatever port it was given (as oMLX does).
- mlxServeDecides joins listsDecisions. fetchDecide reads /v1/models and
  keeps models with the "decisions" capability under <id>.decisions, with
  the model's context window and input modalities.
- DecidesModel takes them out of the agents' chat lists and offers them as
  deciders. Jev() is the first of them. A server with no decision model
  lists none, and no Jev alias is made up for it.
- Provider test on a decision model asks System One rather than chat.

Run:
- TestMlxServeDecisionModels: fake MLX-Serve answers with real captured
  fields. Clef-Flash with capabilities: ["decisions"] is a decider, chat
  models reach agents, and RouteDecider plus AskSystemOne post to
  /v1/systemone. TestModels tests clef-flash-4bit via decide. Red without
  mlxServeDecides in listsDecisions.
- TestListedMLXServeDecideTable: real captured response, vision modalities,
  `models` field fallback with omitted input_modalities, chat-only server,
  empty list, and invalid JSON.
- TestMLXServeWithoutDecisionModels: no decision model means none, not Jev.
- Real MLX-Serve on localhost:11234 in sandbox HOME with isolated config:
  provider add mlx-serve, provider refresh, provider test mlx-serve
  clef-flash-4bit (543 ms, decide OK), group add with classifier.
- go test -tags nogui ./internal/provider/..., gofmt -l, GOOS=linux and
  GOOS=windows go vet, cross-OS builds.
2026-10-13 16:34:59 +08:00

79 lines
2.3 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"
// 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
}