Skip to content

Commit c4f958e

Browse files
authored
refactor(application): introduce application global state (#2072)
* start breaking up the giant channel refactor now that it's better understood - easier to merge bites Signed-off-by: Dave Lee <[email protected]> * add concurrency and base64 back in, along with new base64 tests. Signed-off-by: Dave Lee <[email protected]> * Automatic rename of whisper.go's Result to TranscriptResult Signed-off-by: Dave Lee <[email protected]> * remove pkg/concurrency - significant changes coming in split 2 Signed-off-by: Dave Lee <[email protected]> * fix comments Signed-off-by: Dave Lee <[email protected]> * add list_model service as another low-risk service to get it out of the way Signed-off-by: Dave Lee <[email protected]> * split backend config loader into seperate file from the actual config struct. No changes yet, just reduce cognative load with smaller files of logical blocks Signed-off-by: Dave Lee <[email protected]> * rename state.go ==> application.go Signed-off-by: Dave Lee <[email protected]> * fix lost import? Signed-off-by: Dave Lee <[email protected]> --------- Signed-off-by: Dave Lee <[email protected]>
1 parent 147440b commit c4f958e

File tree

22 files changed

+590
-422
lines changed

22 files changed

+590
-422
lines changed

backend/go/transcribe/transcript.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func audioToWav(src, dst string) error {
2929
return nil
3030
}
3131

32-
func Transcript(model whisper.Model, audiopath, language string, threads uint) (schema.Result, error) {
33-
res := schema.Result{}
32+
func Transcript(model whisper.Model, audiopath, language string, threads uint) (schema.TranscriptionResult, error) {
33+
res := schema.TranscriptionResult{}
3434

3535
dir, err := os.MkdirTemp("", "whisper")
3636
if err != nil {

backend/go/transcribe/whisper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ func (sd *Whisper) Load(opts *pb.ModelOptions) error {
2121
return err
2222
}
2323

24-
func (sd *Whisper) AudioTranscription(opts *pb.TranscriptRequest) (schema.Result, error) {
24+
func (sd *Whisper) AudioTranscription(opts *pb.TranscriptRequest) (schema.TranscriptionResult, error) {
2525
return Transcript(sd.whisper, opts.Dst, opts.Language, uint(opts.Threads))
2626
}

core/application.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package core
2+
3+
import (
4+
"github.com/go-skynet/LocalAI/core/config"
5+
"github.com/go-skynet/LocalAI/core/services"
6+
"github.com/go-skynet/LocalAI/pkg/model"
7+
)
8+
9+
// The purpose of this structure is to hold pointers to all initialized services, to make plumbing easy
10+
// Perhaps a proper DI system is worth it in the future, but for now keep things simple.
11+
type Application struct {
12+
13+
// Application-Level Config
14+
ApplicationConfig *config.ApplicationConfig
15+
// ApplicationState *ApplicationState
16+
17+
// Core Low-Level Services
18+
BackendConfigLoader *config.BackendConfigLoader
19+
ModelLoader *model.ModelLoader
20+
21+
// Backend Services
22+
// EmbeddingsBackendService *backend.EmbeddingsBackendService
23+
// ImageGenerationBackendService *backend.ImageGenerationBackendService
24+
// LLMBackendService *backend.LLMBackendService
25+
// TranscriptionBackendService *backend.TranscriptionBackendService
26+
// TextToSpeechBackendService *backend.TextToSpeechBackendService
27+
28+
// LocalAI System Services
29+
BackendMonitorService *services.BackendMonitorService
30+
GalleryService *services.GalleryService
31+
ListModelsService *services.ListModelsService
32+
LocalAIMetricsService *services.LocalAIMetricsService
33+
// OpenAIService *services.OpenAIService
34+
}
35+
36+
// TODO [NEXT PR?]: Break up ApplicationConfig.
37+
// Migrate over stuff that is not set via config at all - especially runtime stuff
38+
type ApplicationState struct {
39+
}

core/backend/transcript.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
model "github.com/go-skynet/LocalAI/pkg/model"
1212
)
1313

14-
func ModelTranscription(audio, language string, ml *model.ModelLoader, backendConfig config.BackendConfig, appConfig *config.ApplicationConfig) (*schema.Result, error) {
14+
func ModelTranscription(audio, language string, ml *model.ModelLoader, backendConfig config.BackendConfig, appConfig *config.ApplicationConfig) (*schema.TranscriptionResult, error) {
1515

1616
opts := modelOpts(backendConfig, appConfig, []model.Option{
1717
model.WithBackendString(model.WhisperBackend),

0 commit comments

Comments
 (0)