mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-21 05:33:09 +00:00
255748bcba
This PR specifically introduces a `core` folder and moves the following packages over, without any other changes: - `api/backend` - `api/config` - `api/options` - `api/schema` Once this is merged and we confirm there's no regressions, I can migrate over the remaining changes piece by piece to split up application startup, backend services, http, and mqtt as was the goal of the earlier PRs!
40 lines
1006 B
Go
40 lines
1006 B
Go
package backend
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
config "github.com/go-skynet/LocalAI/core/config"
|
|
"github.com/go-skynet/LocalAI/core/schema"
|
|
|
|
"github.com/go-skynet/LocalAI/core/options"
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
|
)
|
|
|
|
func ModelTranscription(audio, language string, loader *model.ModelLoader, c config.Config, o *options.Option) (*schema.Result, error) {
|
|
|
|
opts := modelOpts(c, o, []model.Option{
|
|
model.WithBackendString(model.WhisperBackend),
|
|
model.WithModel(c.Model),
|
|
model.WithContext(o.Context),
|
|
model.WithThreads(uint32(c.Threads)),
|
|
model.WithAssetDir(o.AssetsDestination),
|
|
})
|
|
|
|
whisperModel, err := o.Loader.BackendLoader(opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if whisperModel == nil {
|
|
return nil, fmt.Errorf("could not load whisper model")
|
|
}
|
|
|
|
return whisperModel.AudioTranscription(context.Background(), &proto.TranscriptRequest{
|
|
Dst: audio,
|
|
Language: language,
|
|
Threads: uint32(c.Threads),
|
|
})
|
|
}
|