Files
LocalAI/core/backend/systemone.go
T
mudler-agentandEttore Di Giacinto 39b3b31153 fix(backends): flag a llama-cpp backend that predates native decisions (#12733)
A decision request (/v1/systemone, /v1/decisions) sends Score with
question_type "systemone". A backend built before native decisions ignores
that field and runs plain scoring, so the caller saw "Score was not enabled"
(500) or "candidates must be non-empty" (400). The gallery "latest" image can
lag behind the server, and the upgrade check compares only tag, version and
digest, so /backends/upgrades did not list the backend.

Recognise those two errors for a decision request, return 501 with a message
that says the backend is older than the server and must be upgraded, and mark
the backend stale. The upgrade check now reports a marked backend with a
`reason`, and refreshes at once. Reinstalling the backend drops the mark; if
the new image is still old, the next request marks it again. Model loading is
not affected.

Refreshing the "latest" backend image is a separate publishing step and is
not part of this change.

Refs #12693

Assisted-by: Claude Code:claude-sonnet-5-5 [go vet] [go test]

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-10-16 10:41:45 +02:00

80 lines
2.5 KiB
Go

package backend
import (
"context"
"fmt"
"time"
"github.com/mudler/LocalAI/core/config"
"github.com/mudler/LocalAI/core/trace"
"github.com/mudler/LocalAI/pkg/grpc"
pb "github.com/mudler/LocalAI/pkg/grpc/proto"
model "github.com/mudler/LocalAI/pkg/model"
)
// ModelSystemOne loads the backend for modelConfig and returns a closure
// that runs the kev/laya decision pipeline via the Score gRPC RPC with
// question_type set to "systemone". requestJSON is the raw /v1/systemone
// POST body; the closure returns the full response JSON from the backend.
func ModelSystemOne(requestJSON string, loader *model.ModelLoader, modelConfig config.ModelConfig, appConfig *config.ApplicationConfig) (func(ctx context.Context) (string, error), error) {
modelOpts := ModelOptions(modelConfig, appConfig)
inferenceModel, err := loader.Load(modelOpts...)
if err != nil {
recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
return nil, err
}
b, ok := inferenceModel.(grpc.Backend)
if !ok {
return nil, fmt.Errorf("systemone not supported by backend %q", modelConfig.Backend)
}
return func(ctx context.Context) (string, error) {
if err := ctx.Err(); err != nil {
return "", err
}
release, err := AcquireGlobalBackendSlot()
if err != nil {
return "", err
}
defer release()
var startTime time.Time
var traceID string
if appConfig.EnableTracing {
trace.InitBackendTracingIfEnabled(appConfig.TracingMaxItems, appConfig.TracingMaxBodyBytes)
startTime = time.Now()
traceID = trace.BeginBackendTrace(trace.BackendTrace{
Timestamp: startTime,
Type: trace.BackendTraceScore,
ModelName: modelConfig.Name,
Backend: modelConfig.Backend,
Summary: "native decision request",
})
}
defer trace.CancelBackendTrace(traceID)
resp, err := b.Score(ctx, &pb.ScoreRequest{
Prompt: requestJSON,
QuestionType: "systemone",
ModelIdentity: modelConfig.Model,
})
if appConfig.EnableTracing {
errStr := ""
if err != nil {
errStr = "native decision backend failed"
}
trace.RecordBackendTrace(trace.BackendTrace{
ID: traceID,
Timestamp: startTime,
Duration: time.Since(startTime),
Type: trace.BackendTraceScore,
ModelName: modelConfig.Name,
Backend: modelConfig.Backend,
Summary: "native decision request",
Error: errStr,
})
}
if err != nil {
return "", handleStaleDecisionBackend(modelConfig.Backend, err)
}
return resp.GetResponseJson(), nil
}, nil
}