fix: use exact tag matching for model gallery tag filtering#9041
Open
majiayu000 wants to merge 1 commit intomudler:masterfrom
Open
fix: use exact tag matching for model gallery tag filtering#9041majiayu000 wants to merge 1 commit intomudler:masterfrom
majiayu000 wants to merge 1 commit intomudler:masterfrom
Conversation
The Search() method uses strings.Contains() on comma-joined tags, causing substring false positives (e.g., "asr" matching "image-diffusers"). Add FilterByTag() method that checks each tag with strings.EqualFold() for exact, case-insensitive matching. Add 'tag' query parameter to /api/models and /api/backends endpoints. Update the React frontend to send filter selections as 'tag' instead of 'term'. Closes mudler#8775 Signed-off-by: majiayu000 <1835304752@qq.com>
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Owner
|
rebase is needed @majiayu000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8775
Problem
When browsing the model gallery by tag (e.g. clicking "ASR"), unrelated models are returned. The root cause is in
core/gallery/gallery.gowhereSearch()joins all tags into a single comma-separated string and usesstrings.Contains()for matching. This means searching for "asr" matches any model whose joined tag string contains that substring — for example, "image-diffusers" matches because the joined string contains "asr" as a substring.Fix
core/gallery/gallery.go — Added
FilterByTag()method that does exact case-insensitive comparison (strings.EqualFold) against individual tags instead of substring matching on a joined string.core/http/routes/ui_api.go — Added
tagquery parameter toGET /api/modelsandGET /api/backends. Whentagis provided,FilterByTag()is used for exact matching. The existingtermparameter continues to work as before for fuzzy text search.core/http/react-ui/src/pages/Models.jsx — Filter button clicks now send
?tag=instead of?term=, so tag selections use exact matching while the search box continues to use fuzzy search.core/gallery/gallery_test.go — Added tests for
FilterByTag()covering exact match, case insensitivity, substring non-match (key regression: model with tag "image-diffusers" must NOT match filter "asr"), empty results, and multiple matches.