LocalAI icon indicating copy to clipboard operation
LocalAI copied to clipboard

feat: Centralized Request Processing middleware

Open dave-gray101 opened this issue 1 year ago • 3 comments

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!

dave-gray101 avatar Oct 16 '24 07:10 dave-gray101

Deploy Preview for localai ready!

Name Link
Latest commit f7dab99d80f4b2bc45d249406fa7684b651261cf
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.

netlify[bot] avatar Oct 16 '24 07:10 netlify[bot]

~~@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 avatar Nov 21 '24 07:11 dave-gray101

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

dave-gray101 avatar Dec 18 '24 01:12 dave-gray101

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!

dave-gray101 avatar Feb 05 '25 19:02 dave-gray101

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 !

mudler avatar Feb 06 '25 18:02 mudler