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

refactor: ListModels Filtering Upgrade #2773

Merged
merged 67 commits into from
Oct 1, 2024

Conversation

dave-gray101
Copy link
Collaborator

Description

This PR introduces just the ListModels and config package changes from my earlier middleware PR. In order to manage size and conflicts, this PR does not use Usecase-based filtering yet - simply migrates existing name based filtering to the new style and sets up the initial test to prove usecases are working.

In the upcoming [new] middleware PR, default models will take this into account and we can drive better dropdowns on the UI as well.

@dave-gray101 dave-gray101 requested a review from mudler July 11, 2024 18:51
Copy link

netlify bot commented Jul 11, 2024

Deploy Preview for localai ready!

Name Link
🔨 Latest commit 68a1006
🔍 Latest deploy log https://app.netlify.com/sites/localai/deploys/66fc2f5e9ad8ca00086c03ac
😎 Deploy Preview https://deploy-preview-2773--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 dave-gray101 enabled auto-merge (squash) July 11, 2024 19:12
@dave-gray101 dave-gray101 changed the title groundwork: ListModels Filtering Upgrade refactoring: groundwork: ListModels Filtering Upgrade Jul 12, 2024
@dave-gray101 dave-gray101 changed the title refactoring: groundwork: ListModels Filtering Upgrade refactoring: groundwork - ListModels Filtering Upgrade Jul 12, 2024
@dave-gray101 dave-gray101 changed the title refactoring: groundwork - ListModels Filtering Upgrade refactor: groundwork: ListModels Filtering Upgrade Jul 12, 2024
@dave-gray101 dave-gray101 changed the title refactor: groundwork: ListModels Filtering Upgrade refactor: groundwork - ListModels Filtering Upgrade Jul 12, 2024
@dave-gray101 dave-gray101 changed the title refactor: groundwork - ListModels Filtering Upgrade refactor: ListModels Filtering Upgrade Jul 12, 2024
@dave-gray101
Copy link
Collaborator Author

@mudler mind reviewing this when you get a chance? It's been sitting a while, so I did just merge master to shake out the dust.

//
// In its current state, this function should ideally check for properties of the config like templates, rather than the direct backend name checks for the lower half.
// This avoids the maintenance burden of updating this list for each new backend - but unfortunately, that's the best option for some services currently.
func (c *BackendConfig) HasUsecases(u BackendConfigUsecases) bool {
Copy link
Owner

@mudler mudler Sep 27, 2024

Choose a reason for hiding this comment

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

My two cents on this - I would expect a "category" field on the backend config at this point. Hooking into the backend name can be brittle, mainly because a user might expand backends with --external-backends. Maybe we can mix (detection) and explicit configuration via backend config?

Copy link
Collaborator Author

@dave-gray101 dave-gray101 Sep 27, 2024

Choose a reason for hiding this comment

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

As I mentioned in that comment, I'm significantly concerned with the maintenance burden of our yaml config backlog [to either initially create it, or update if new backends are created].

I see a few paths forward:

  • We could ignore heuristics if category is set - this is the simplest and sanest option, but it's got possible future tech debt in the form of "we add a new usecase" or any other major breaking change. Existing yaml configs would run through the heuristic, but new ones could be created to bypass it.
  • We could just use both. If a model has a category field, we also run it through heuristics and use the union. At worst, we show a model in a place it's not super useful, which is what we currently do everywhere. This is my current plan
    • PR updated to demonstrate this
  • A more dramatic solution would be to adapt this heuristic function to a "one off" script that we could run against existing gallery files. If we added the category field to everything that exists today, we could mandate that it's a requirement going forward, and eliminate the need for runtime scanning. This does run the risk of "new usecase tech debt", but it seems saner to require an "update the gallery" script?

Copy link
Owner

@mudler mudler left a comment

Choose a reason for hiding this comment

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

Liking this 💯 !

}
}
if (u & FLAG_TTS) == FLAG_TTS {
ttsBackends := []string{"piper", "transformers-musicgen", "parler-tts"}
Copy link
Owner

Choose a reason for hiding this comment

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

another optimization down the line is to extract the backend list here at the top of the file in a map or either a list for easing out maintenance

Copy link
Collaborator Author

@dave-gray101 dave-gray101 Oct 1, 2024

Choose a reason for hiding this comment

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

I like that idea. I plan to do some more refactoring around the services, and I think the best place to locate that list will be over there. Thanks!

ttsService.GetKnownBackends() or something similar - not ruling out putting it above here, just seems a bit strange to maintain an ongoing list of backends in the config subdir :)

@mudler
Copy link
Owner

mudler commented Oct 1, 2024

this coqui test started to be flaky lately, ugh

@@ -21,12 +21,12 @@ func ModelFromContext(ctx *fiber.Ctx, cl *config.BackendConfigLoader, loader *mo
}

// Set model from bearer token, if available
bearer := strings.TrimLeft(ctx.Get("authorization"), "Bearer ")
bearer := strings.TrimLeft(ctx.Get("authorization"), "Bear ") // Reduced duplicate characters of Bearer
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't this breaking?

Copy link
Collaborator Author

@dave-gray101 dave-gray101 Oct 1, 2024

Choose a reason for hiding this comment

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

Interesting enough it is not. The static analysis tooling we've been experimenting with pointed this out to me and I verified it in the golang source: https://github.com/golang/go/blob/master/src/strings/strings.go

TrimLeft (and its many friends) iterate through the string a single time, checking every character. If that character is contained in the "cutset" string even once, it will be removed. No need for duplicated characters - they will be scanned M*N every time its called, without benefit. This example is B e a r er

@mudler mudler added the enhancement New feature or request label Oct 1, 2024
@dave-gray101
Copy link
Collaborator Author

this coqui test started to be flaky lately, ugh

I have been baby sitting that one for a few weeks now - it's unfortunately not related to PR content and is something we'll need to address separately.

@dave-gray101 dave-gray101 merged commit 307a835 into mudler:master Oct 1, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants