Skip to content

Commit

Permalink
refactor(application): introduce application global state (#2072)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dave-gray101 authored Apr 29, 2024
1 parent 147440b commit c4f958e
Show file tree
Hide file tree
Showing 22 changed files with 590 additions and 422 deletions.
4 changes: 2 additions & 2 deletions backend/go/transcribe/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func audioToWav(src, dst string) error {
return nil
}

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

dir, err := os.MkdirTemp("", "whisper")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion backend/go/transcribe/whisper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (sd *Whisper) Load(opts *pb.ModelOptions) error {
return err
}

func (sd *Whisper) AudioTranscription(opts *pb.TranscriptRequest) (schema.Result, error) {
func (sd *Whisper) AudioTranscription(opts *pb.TranscriptRequest) (schema.TranscriptionResult, error) {
return Transcript(sd.whisper, opts.Dst, opts.Language, uint(opts.Threads))
}
39 changes: 39 additions & 0 deletions core/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package core

import (
"github.com/go-skynet/LocalAI/core/config"
"github.com/go-skynet/LocalAI/core/services"
"github.com/go-skynet/LocalAI/pkg/model"
)

// The purpose of this structure is to hold pointers to all initialized services, to make plumbing easy
// Perhaps a proper DI system is worth it in the future, but for now keep things simple.
type Application struct {

// Application-Level Config
ApplicationConfig *config.ApplicationConfig
// ApplicationState *ApplicationState

// Core Low-Level Services
BackendConfigLoader *config.BackendConfigLoader
ModelLoader *model.ModelLoader

// Backend Services
// EmbeddingsBackendService *backend.EmbeddingsBackendService
// ImageGenerationBackendService *backend.ImageGenerationBackendService
// LLMBackendService *backend.LLMBackendService
// TranscriptionBackendService *backend.TranscriptionBackendService
// TextToSpeechBackendService *backend.TextToSpeechBackendService

// LocalAI System Services
BackendMonitorService *services.BackendMonitorService
GalleryService *services.GalleryService
ListModelsService *services.ListModelsService
LocalAIMetricsService *services.LocalAIMetricsService
// OpenAIService *services.OpenAIService
}

// TODO [NEXT PR?]: Break up ApplicationConfig.
// Migrate over stuff that is not set via config at all - especially runtime stuff
type ApplicationState struct {
}
2 changes: 1 addition & 1 deletion core/backend/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
model "github.com/go-skynet/LocalAI/pkg/model"
)

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

opts := modelOpts(backendConfig, appConfig, []model.Option{
model.WithBackendString(model.WhisperBackend),
Expand Down
Loading

0 comments on commit c4f958e

Please sign in to comment.