mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-22 06:04:55 -04:00
Report input tokens and frame-step output units in response metadata and record them through the existing usage accounting pipeline. Preserve the accounting rule and model-specific dimensions as JSON without extending the gRPC schema for each modality. Expose animation usage only under metadata.usage, validate counts before recording, and document the response contract and loaded-model location. Add coverage for transport, defaults, failures, persistence, and recording requests once with statistics enabled or disabled. Assisted-by: Codex:GPT-6 Signed-off-by: Richard Palethorpe <io@richiejp.com>
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
// SPDX-License-Identifier: MIT
|
|
package backend
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
"github.com/mudler/LocalAI/core/trace"
|
|
"github.com/mudler/LocalAI/pkg/grpc/proto"
|
|
"github.com/mudler/LocalAI/pkg/model"
|
|
)
|
|
|
|
func Model3DAnimation(ctx context.Context, request *proto.Animate3DRequest, loader *model.ModelLoader, modelConfig config.ModelConfig, appConfig *config.ApplicationConfig) (responseMetadata []byte, err error) {
|
|
inferenceModel, err := loader.Load(ModelOptions(modelConfig, appConfig)...)
|
|
if err != nil {
|
|
recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
|
|
return nil, err
|
|
}
|
|
release, err := AcquireGlobalBackendSlot()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer release()
|
|
if appConfig.EnableTracing {
|
|
trace.InitBackendTracingIfEnabled(appConfig.TracingMaxItems, appConfig.TracingMaxBodyBytes)
|
|
start := time.Now()
|
|
entry := trace.BackendTrace{Timestamp: start, Type: trace.BackendTrace3DAnimation, ModelName: modelConfig.Name, Backend: modelConfig.Backend, Summary: "3d: animate"}
|
|
entry.ID = trace.BeginBackendTrace(entry)
|
|
defer trace.CancelBackendTrace(entry.ID)
|
|
defer func() {
|
|
entry.Duration = time.Since(start)
|
|
if err != nil {
|
|
entry.Error = err.Error()
|
|
}
|
|
trace.RecordBackendTrace(entry)
|
|
}()
|
|
}
|
|
request.ModelIdentity = modelConfig.Model
|
|
result, err := inferenceModel.Animate3D(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if result == nil || !result.Success {
|
|
return nil, fmt.Errorf("animation backend failed: %s", result.GetMessage())
|
|
}
|
|
return result.Metadata, nil
|
|
}
|