Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: Centralized Request Processing middleware#3847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c1f30ba5e07c3c5b01500aa9c995cac5f5aa33a4d5b717f6ff7dab99File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| backend: silero-vad | ||
| name: silero-vad | ||
| parameters: | ||
| model: silero-vad.onnx | ||
| download_files: | ||
| - filename: silero-vad.onnx | ||
| uri: https://huggingface.co/onnx-community/silero-vad/resolve/main/onnx/model.onnx | ||
| sha256: a4a068cd6cf1ea8355b84327595838ca748ec29a25bc91fc82e6c299ccdc5808 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| backend: silero-vad | ||
| name: silero-vad | ||
| parameters: | ||
| model: silero-vad.onnx | ||
| download_files: | ||
| - filename: silero-vad.onnx | ||
| uri: https://huggingface.co/onnx-community/silero-vad/resolve/main/onnx/model.onnx | ||
| sha256: a4a068cd6cf1ea8355b84327595838ca748ec29a25bc91fc82e6c299ccdc5808 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| backend: silero-vad | ||
| name: silero-vad | ||
| parameters: | ||
| model: silero-vad.onnx | ||
| download_files: | ||
| - filename: silero-vad.onnx | ||
| uri: https://huggingface.co/onnx-community/silero-vad/resolve/main/onnx/model.onnx | ||
| sha256: a4a068cd6cf1ea8355b84327595838ca748ec29a25bc91fc82e6c299ccdc5808 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -145,13 +145,7 @@ func New(opts ...config.AppOption) (*Application, error) { | ||
| if options.LoadToMemory != nil { | ||
| for _, m := range options.LoadToMemory { | ||
| cfg, err := application.BackendLoader().LoadBackendConfigFileByName(m, options.ModelPath, | ||
| config.LoadOptionDebug(options.Debug), | ||
| config.LoadOptionThreads(options.Threads), | ||
| config.LoadOptionContextSize(options.ContextSize), | ||
| config.LoadOptionF16(options.F16), | ||
| config.ModelPath(options.ModelPath), | ||
| ) | ||
| cfg, err := application.BackendLoader().LoadBackendConfigFileByNameDefaultOptions(m, options) | ||
Owner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 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, | ||
| backendConfig config.BackendConfig) (*schema.VADResponse, error) { | ||
| opts := ModelOptions(backendConfig, 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 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -437,19 +437,21 @@ func (c *BackendConfig) HasTemplate() bool { | ||
| type BackendConfigUsecases int | ||
| const ( | ||
| FLAG_ANY BackendConfigUsecases = 0b000000000 | ||
| FLAG_CHAT BackendConfigUsecases = 0b000000001 | ||
| FLAG_COMPLETION BackendConfigUsecases = 0b000000010 | ||
| FLAG_EDIT BackendConfigUsecases = 0b000000100 | ||
| FLAG_EMBEDDINGS BackendConfigUsecases = 0b000001000 | ||
| FLAG_RERANK BackendConfigUsecases = 0b000010000 | ||
| FLAG_IMAGE BackendConfigUsecases = 0b000100000 | ||
| FLAG_TRANSCRIPT BackendConfigUsecases = 0b001000000 | ||
| FLAG_TTS BackendConfigUsecases = 0b010000000 | ||
| FLAG_SOUND_GENERATION BackendConfigUsecases = 0b100000000 | ||
| FLAG_ANY BackendConfigUsecases = 0b00000000000 | ||
| FLAG_CHAT BackendConfigUsecases = 0b00000000001 | ||
| FLAG_COMPLETION BackendConfigUsecases = 0b00000000010 | ||
| FLAG_EDIT BackendConfigUsecases = 0b00000000100 | ||
| FLAG_EMBEDDINGS BackendConfigUsecases = 0b00000001000 | ||
| FLAG_RERANK BackendConfigUsecases = 0b00000010000 | ||
| FLAG_IMAGE BackendConfigUsecases = 0b00000100000 | ||
| FLAG_TRANSCRIPT BackendConfigUsecases = 0b00001000000 | ||
| FLAG_TTS BackendConfigUsecases = 0b00010000000 | ||
| FLAG_SOUND_GENERATION BackendConfigUsecases = 0b00100000000 | ||
| FLAG_TOKENIZE BackendConfigUsecases = 0b01000000000 | ||
| FLAG_VAD BackendConfigUsecases = 0b10000000000 | ||
| // Common Subsets | ||
| FLAG_LLM BackendConfigUsecases = FLAG_CHAT & FLAG_COMPLETION & FLAG_EDIT | ||
| FLAG_LLM BackendConfigUsecases = FLAG_CHAT | FLAG_COMPLETION | FLAG_EDIT | ||
| ) | ||
| func GetAllBackendConfigUsecases() map[string]BackendConfigUsecases { | ||
| @@ -464,6 +466,8 @@ func GetAllBackendConfigUsecases() map[string]BackendConfigUsecases { | ||
| "FLAG_TRANSCRIPT": FLAG_TRANSCRIPT, | ||
| "FLAG_TTS": FLAG_TTS, | ||
| "FLAG_SOUND_GENERATION": FLAG_SOUND_GENERATION, | ||
| "FLAG_TOKENIZE": FLAG_TOKENIZE, | ||
| "FLAG_VAD": FLAG_VAD, | ||
| "FLAG_LLM": FLAG_LLM, | ||
| } | ||
| } | ||
| @@ -549,5 +553,18 @@ func (c *BackendConfig) GuessUsecases(u BackendConfigUsecases) bool { | ||
| } | ||
| } | ||
| if (u & FLAG_TOKENIZE) == FLAG_TOKENIZE { | ||
| tokenizeCapableBackends := []string{"llama.cpp", "rwkv"} | ||
| if !slices.Contains(tokenizeCapableBackends, c.Backend) { | ||
| return false | ||
| } | ||
| } | ||
| if (u & FLAG_VAD) == FLAG_VAD { | ||
| if c.Backend != "silero-vad" { | ||
Owner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for later: at some point we should think about having these constants defined to be re-usable. There are some repetitions as well in the model initializer ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - probably worth doing that as followup if you're OK with that Owner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. definitely, was just a reminder/note | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍