Skip to content

Add "Sort by Size" to the model selection menu - #124

Merged
Blaizzy merged 2 commits into
mainfrom
feat/sort-by-size
Jul 27, 2026
Merged

Add "Sort by Size" to the model selection menu#124
Blaizzy merged 2 commits into
mainfrom
feat/sort-by-size

Conversation

@Lazarus-931

Copy link
Copy Markdown
Collaborator

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 .size fetches by downloads (a valid API sort) and re-sorts the fetched results client-side by size — smallest first, with unknown sizes last — using the safetensors size metadata the search already requests (expand[]=safetensors). Pagination re-orders the accumulated buffer, so paging stays consistent.

Scope: one new enum case (HuggingFaceModelSort.size) + an orderedBuffer in HuggingFaceModelLibrary; the sort picker picks it up automatically via allCases.

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.
@Lazarus-931
Lazarus-931 requested a review from Blaizzy July 27, 2026 16:11

@Blaizzy Blaizzy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@lucasnewman could you check this change?

var queryItems = [
URLQueryItem(name: "filter", value: "safetensors"),
URLQueryItem(name: "sort", value: sort.rawValue),
URLQueryItem(name: "sort", value: sort.apiValue),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Revert


/// 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).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

short comment

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
Blaizzy merged commit 9b739c3 into main Jul 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Sort by Model Size (Gb) in selection menu

2 participants