Add "Sort by Size" to the model selection menu - #124
Merged
Conversation
Resolves #120. Adds a Size option to the Discover sort menu so users can find models that fit their memory. Hugging Face's search API can't sort by model size, so this fetches by downloads and re-sorts the fetched results client-side by size (smallest first; unknown sizes last), using the safetensors metadata the search already requests.
Blaizzy
reviewed
Jul 27, 2026
Blaizzy
left a comment
Owner
There was a problem hiding this comment.
LGTM, but I have one part where the comment is a bit odd, so @lucasnewman will double check.
| /// downloads and the results are re-sorted client-side. | ||
| var apiValue: String { | ||
| self == .size ? Self.downloads.rawValue : rawValue | ||
| } |
Blaizzy
reviewed
Jul 27, 2026
| var queryItems = [ | ||
| URLQueryItem(name: "filter", value: "safetensors"), | ||
| URLQueryItem(name: "sort", value: sort.rawValue), | ||
| URLQueryItem(name: "sort", value: sort.apiValue), |
Blaizzy
reviewed
Jul 27, 2026
|
|
||
| /// The buffered results in display order. Hugging Face can't sort by size, so the | ||
| /// `.size` sort re-orders the fetched results locally (smallest first; models whose | ||
| /// size is unknown go last). |
HF ignores an unknown sort value and results are re-sorted client-side, so the apiValue mapping was unnecessary; send sort.rawValue directly again.
Blaizzy
approved these changes
Jul 27, 2026
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.
Resolves #120.
Adds a Size option to the Discover "Sort by" menu so users can quickly find models that fit their hardware (RAM/VRAM).
How: Hugging Face's search API doesn't support sorting by model size, so
.sizefetches by downloads (a valid API sort) and re-sorts the fetched results client-side by size — smallest first, with unknown sizes last — using thesafetensorssize metadata the search already requests (expand[]=safetensors). Pagination re-orders the accumulated buffer, so paging stays consistent.Scope: one new enum case (
HuggingFaceModelSort.size) + anorderedBufferinHuggingFaceModelLibrary; the sort picker picks it up automatically viaallCases.