mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-05 13:57:28 -04:00
Replaces remaining context.Background() sites in core/backend with the caller's ctx. After this commit, every core/backend/*.go entry point threads the request ctx end-to-end to the gRPC client. Assisted-by: Claude:claude-haiku-4-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
34 lines
768 B
Go
34 lines
768 B
Go
package backend
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
"github.com/mudler/LocalAI/pkg/grpc/proto"
|
|
model "github.com/mudler/LocalAI/pkg/model"
|
|
)
|
|
|
|
func TokenMetrics(
|
|
ctx context.Context,
|
|
modelFile string,
|
|
loader *model.ModelLoader,
|
|
appConfig *config.ApplicationConfig,
|
|
modelConfig config.ModelConfig) (*proto.MetricsResponse, error) {
|
|
|
|
opts := ModelOptions(modelConfig, appConfig, model.WithModel(modelFile))
|
|
model, err := loader.Load(opts...)
|
|
if err != nil {
|
|
recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
|
|
return nil, err
|
|
}
|
|
|
|
if model == nil {
|
|
return nil, fmt.Errorf("could not loadmodel model")
|
|
}
|
|
|
|
res, err := model.GetTokenMetrics(ctx, &proto.MetricsRequest{})
|
|
|
|
return res, err
|
|
}
|