Skip to content
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

feat: Centralized Request Processing middleware #3847

Merged
merged 8 commits into from
Feb 10, 2025

Conversation

dave-gray101
Copy link
Collaborator

@dave-gray101 dave-gray101 commented Oct 16, 2024

This PR reworks how our endpoints parse and process user input, in order to centralize and commonize that code as much as possible. This will drastically cut down the endpoint-specific code to a minimum.

Additionally, the VAD subsystem was untested - making it hard to validate if this changeset was safe or not. Therefore, this PR also adds both manual testing tools (via bruno) and automated testing in the AIO image.


Note to @mudler - this PR looks worse than it is - here's some reviewing notes to help

  • core/http/middleware/request.go should be where you start - its the heart of the change and replaces core/http/ctx/fiber.go
  • configuration of defaults is now a responsibility of the route function - seems a bit weird at first, but allows endpoints to be easily reused with different defaults on different paths.
  • while all the endpoint files were updated, the changes all follow the same pattern:
    • A new standard header to the function was added which pulls the relevant input and config from the earlier middleware stage
    • A bunch of code is deleted as its now performed earlier by those middlewares
    • The functional code specific to the endpoint is unchanged except for variable references
  • Specific to the AIO CI test: I was seeing very unpredictable behavior on CI versus locally reproducing this test. It turns out that setting LOCALAI_SINGLE_ACTIVE_BACKEND=true helps with a memory usage issue!

Copy link

netlify bot commented Oct 16, 2024

Deploy Preview for localai ready!

Name Link
🔨 Latest commit f7dab99
🔍 Latest deploy log https://app.netlify.com/sites/localai/deploys/67a9c57513819e00084f4390
😎 Deploy Preview https://deploy-preview-3847--localai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dave-gray101
Copy link
Collaborator Author

dave-gray101 commented Nov 21, 2024

@mudler merged in VAD, but I don't know how to test it manually yet since it's new. Please double check that :)

@dave-gray101 dave-gray101 force-pushed the feat-request-middleware branch 2 times, most recently from df37c12 to d08311f Compare December 17, 2024 20:06
@dave-gray101
Copy link
Collaborator Author

@mudler Ready for review, now with working VAD test.

@dave-gray101 dave-gray101 force-pushed the feat-request-middleware branch from 6050d80 to c1f30ba Compare February 5, 2025 19:14
@dave-gray101
Copy link
Collaborator Author

merged and squashed this again.

@mudler - Can you decide if this PR is worth maintaining? It's been stable through my testing for a while now. I'd like to either find a merge window for this, or just scrap it if you dislike the central concept. Thanks!

@mudler
Copy link
Owner

mudler commented Feb 6, 2025

merged and squashed this again.

@mudler - Can you decide if this PR is worth maintaining? It's been stable through my testing for a while now. I'd like to either find a merge window for this, or just scrap it if you dislike the central concept. Thanks!

Just had a quick look now and direction looks good, however since changes are big I need to take a closer look, I'll try to do this asap in these days as now would be a good merge window !

@@ -0,0 +1,8 @@
backend: silero-vad
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

config.LoadOptionF16(options.F16),
config.ModelPath(options.ModelPath),
)
cfg, err := application.BackendLoader().LoadBackendConfigFileByNameDefaultOptions(m, options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


inferenceModel, err = loader.Load(opts...)
// TODO: looks weird, seems to be a correct merge?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks going behind in history. this switch isn't needed anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have corrected this :)

@@ -145,6 +147,15 @@ func (bcl *BackendConfigLoader) LoadBackendConfigFileByName(modelName, modelPath
return cfg, nil
}

func (bcl *BackendConfigLoader) LoadBackendConfigFileByNameDefaultOptions(modelName string, appConfig *ApplicationConfig) (*BackendConfig, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup really appreciated!

}

if (u & FLAG_VAD) == FLAG_VAD {
if c.Backend != "silero-vad" {
Copy link
Owner

@mudler mudler Feb 6, 2025

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely, was just a reminder/note

tests/e2e-aio/e2e_test.go Outdated Show resolved Hide resolved
Signed-off-by: Ettore Di Giacinto <[email protected]>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems quite huge as a text golang file - can we maybe add the converted file to the repo in the fixture folder?

@mudler mudler disabled auto-merge February 10, 2025 11:06
@mudler mudler merged commit 3cddf24 into mudler:master Feb 10, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants