mirror of
https://github.com/mudler/LocalAI.git
synced 2026-01-06 02:29:54 -06:00
* feat(loader): refactor single active backend support to LRU This changeset introduces LRU management of loaded backends. Users can set now a maximum number of models to be loaded concurrently, and, when setting LocalAI in single active backend mode we set LRU to 1 for backward compatibility. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: add tests Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Update docs Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
40 lines
892 B
Go
40 lines
892 B
Go
package backend
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
"github.com/mudler/LocalAI/core/schema"
|
|
"github.com/mudler/LocalAI/pkg/grpc/proto"
|
|
"github.com/mudler/LocalAI/pkg/model"
|
|
)
|
|
|
|
func VAD(request *schema.VADRequest,
|
|
ctx context.Context,
|
|
ml *model.ModelLoader,
|
|
appConfig *config.ApplicationConfig,
|
|
modelConfig config.ModelConfig) (*schema.VADResponse, error) {
|
|
opts := ModelOptions(modelConfig, appConfig)
|
|
vadModel, err := ml.Load(opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req := proto.VADRequest{
|
|
Audio: request.Audio,
|
|
}
|
|
resp, err := vadModel.VAD(ctx, &req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
segments := []schema.VADSegment{}
|
|
for _, s := range resp.Segments {
|
|
segments = append(segments, schema.VADSegment{Start: s.Start, End: s.End})
|
|
}
|
|
|
|
return &schema.VADResponse{
|
|
Segments: segments,
|
|
}, nil
|
|
}
|