mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-25 07:34:58 -04:00
Wire the kev/laya SystemOne decision pipeline and the cua-s1-forms Score primitive through the vllm-cpp backend: - Add SystemOneRequest/SystemOneResponse messages and rpc SystemOne to backend.proto - Add SystemOneModel and ScoreModel optional interfaces in pkg/grpc (follows the ClassifyModel pattern — does not break existing backends) - Add delegating SystemOne and Score methods on the gRPC server struct (previously fell through to UnimplementedBackendServer) - Implement SystemOne (JSON pass-through to vllm_systemone C ABI) and Score (vllm_score C ABI, probabilities to log-probs) in the vllm-cpp backend - Add purego bindings for vllm_systemone/vllm_score (ABI v28) in govllmcpp.go - Add MethodSystemOne to backend capabilities; update vllm-cpp to declare MethodScore, MethodSystemOne, UsecaseScore - Route /v1/systemone to gRPC SystemOne for vllm-cpp models, falling through to the NER-based path for other backends - Add core/backend/systemone.go (ModelSystemOne loader closure) - Fix validModelPath to accept cua-s1-forms.json and rl_agent_config.json alongside config.json - Use -999.0 sentinel instead of -Inf for log(0) in Score (JSON cannot encode Inf) Assisted-by: Maki:regolo/glm5.2 [maki]
76 lines
2.3 KiB
Go
76 lines
2.3 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 SystemOne gRPC RPC.
|
|
// 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) {
|
|
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: trace.TruncateString(requestJSON, 200),
|
|
})
|
|
}
|
|
defer trace.CancelBackendTrace(traceID)
|
|
resp, err := b.SystemOne(ctx, &pb.SystemOneRequest{
|
|
RequestJson: requestJSON,
|
|
ModelIdentity: modelConfig.Model,
|
|
})
|
|
if appConfig.EnableTracing {
|
|
errStr := ""
|
|
if err != nil {
|
|
errStr = err.Error()
|
|
}
|
|
trace.RecordBackendTrace(trace.BackendTrace{
|
|
ID: traceID,
|
|
Timestamp: startTime,
|
|
Duration: time.Since(startTime),
|
|
Type: trace.BackendTraceScore,
|
|
ModelName: modelConfig.Name,
|
|
Backend: modelConfig.Backend,
|
|
Summary: trace.TruncateString(requestJSON, 200),
|
|
Error: errStr,
|
|
})
|
|
}
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return resp.GetResponseJson(), nil
|
|
}, nil
|
|
}
|