Open a repository beneath its row in the mirror's listing
Clicking a repository in the explorer shows its card and files in a row beneath it, fetched from /admin/mirror/repo, and a second click closes it; the list stays where it was. The link still leads to the repository's own page without script or with a modifier key. A repository's files now take one line each, and an importance matrix published beside the quantisations is marked as not a model rather than offered for fetching. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3fea39feb9
commit
ff86e52126
4 files changed
+211
-69
No files matched your search
@@ -123,6 +123,9 @@ type adminMirrorData struct {
|
||||
Explore *explorer
|
||||
// Back is the listing an open repository was reached from.
|
||||
Back template.URL
|
||||
// Inline is a repository rendered beneath its row in the listing, without
|
||||
// the page around it.
|
||||
Inline bool
|
||||
// Card is the open repository's model card, rendered.
|
||||
Card template.HTML
|
||||
// RepoURL is the open repository on the registry's own site.
|
||||
@@ -179,6 +182,23 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
|
||||
p.renderMirror(w, r, m, "", "")
|
||||
}))
|
||||
|
||||
// One repository as a fragment, for the row beneath it in the listing.
|
||||
mux.HandleFunc("GET /admin/mirror/repo", p.adminOnly(
|
||||
func(w http.ResponseWriter, r *http.Request, _ store.User) {
|
||||
repo := strings.TrimSpace(r.URL.Query().Get("repo"))
|
||||
if p.registry == nil || repo == "" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
d := adminMirrorData{CSRF: csrfFor(r), Inline: true, HasRegistry: true}
|
||||
p.openRepo(r, &d, repo)
|
||||
if d.RegistryErr != "" {
|
||||
http.Error(w, "The registry: "+d.RegistryErr, http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
render(w, "mirror_repo", d)
|
||||
}))
|
||||
|
||||
mux.HandleFunc("POST /admin/mirror/fetch", p.mirrorAction(m,
|
||||
func(ctx context.Context, admin store.User, r *http.Request) (string, error) {
|
||||
// One form posts one source or fifteen. A sharded model is one
|
||||
@@ -464,46 +484,52 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) {
|
||||
|
||||
if repo := strings.TrimSpace(r.URL.Query().Get("repo")); repo != "" {
|
||||
d.Back = exploreState(r.URL.Query()).href(d.Query, "", "")
|
||||
got, err := p.registry.Repo(r.Context(), repo)
|
||||
if err != nil {
|
||||
d.RegistryErr = err.Error()
|
||||
return
|
||||
}
|
||||
d.Repo = &got
|
||||
d.RepoURL = strings.TrimSuffix(got.DownloadURL("", ""), "/resolve/"+revOrMain(got.Revision)+"/")
|
||||
d.Card = renderCard(got.Card, d.RepoURL+"/blob/"+revOrMain(got.Revision)+"/")
|
||||
var weights []hf.File
|
||||
for _, f := range got.Files {
|
||||
if !f.IsWeights() {
|
||||
// Thirty files of which four are worth gigabytes. The rest are
|
||||
// a README and a tokenizer, and listing them buries the ones
|
||||
// somebody came for.
|
||||
continue
|
||||
}
|
||||
weights = append(weights, f)
|
||||
}
|
||||
for _, set := range hf.Group(weights) {
|
||||
rs := repoSet{
|
||||
FileSet: set,
|
||||
Model: defaultModelName(got.ID),
|
||||
// The revision, not the date: two fetches of the same commit
|
||||
// land in the same place, and a repository re-uploaded under
|
||||
// the same branch lands somewhere else.
|
||||
Version: got.ShortRevision(),
|
||||
}
|
||||
rs.Verdict = p.verdictFor(got.Architecture, set.Name)
|
||||
for _, f := range set.Files {
|
||||
rs.Sources = append(rs.Sources,
|
||||
repoSource{URL: got.DownloadURL("", f.Path), Path: f.Path})
|
||||
}
|
||||
d.RepoSets = append(d.RepoSets, rs)
|
||||
}
|
||||
p.openRepo(r, d, repo)
|
||||
return
|
||||
}
|
||||
|
||||
p.exploreList(r, d)
|
||||
}
|
||||
|
||||
// openRepo reads one repository: its card, and its weights grouped into what
|
||||
// can be fetched.
|
||||
func (p *AccountPages) openRepo(r *http.Request, d *adminMirrorData, repo string) {
|
||||
got, err := p.registry.Repo(r.Context(), repo)
|
||||
if err != nil {
|
||||
d.RegistryErr = err.Error()
|
||||
return
|
||||
}
|
||||
d.Repo = &got
|
||||
d.RepoURL = strings.TrimSuffix(got.DownloadURL("", ""), "/resolve/"+revOrMain(got.Revision)+"/")
|
||||
d.Card = renderCard(got.Card, d.RepoURL+"/blob/"+revOrMain(got.Revision)+"/")
|
||||
var weights []hf.File
|
||||
for _, f := range got.Files {
|
||||
if !f.IsWeights() {
|
||||
// Thirty files of which four are worth gigabytes. The rest are
|
||||
// a README and a tokenizer, and listing them buries the ones
|
||||
// somebody came for.
|
||||
continue
|
||||
}
|
||||
weights = append(weights, f)
|
||||
}
|
||||
for _, set := range hf.Group(weights) {
|
||||
rs := repoSet{
|
||||
FileSet: set,
|
||||
Model: defaultModelName(got.ID),
|
||||
// The revision, not the date: two fetches of the same commit
|
||||
// land in the same place, and a repository re-uploaded under
|
||||
// the same branch lands somewhere else.
|
||||
Version: got.ShortRevision(),
|
||||
}
|
||||
rs.Verdict = p.verdictFor(got.Architecture, set.Name)
|
||||
for _, f := range set.Files {
|
||||
rs.Sources = append(rs.Sources,
|
||||
repoSource{URL: got.DownloadURL("", f.Path), Path: f.Path})
|
||||
}
|
||||
d.RepoSets = append(d.RepoSets, rs)
|
||||
}
|
||||
}
|
||||
|
||||
// defaultModelName is the catalog name a repository suggests.
|
||||
//
|
||||
// The last element, lowercased, with the quantisation marker dropped: the owner
|
||||
@@ -523,6 +549,12 @@ func (p *AccountPages) verdictFor(arch, name string) gguf.Verdict {
|
||||
if strings.Contains(strings.ToLower(name), "mmproj") {
|
||||
return gguf.LlamaCpp(p.llamaVersion, "clip")
|
||||
}
|
||||
// Published beside the quantisations they were made with, and a GGUF
|
||||
// file like them, so the repository's architecture would pass it.
|
||||
if strings.Contains(strings.ToLower(name), "imatrix") {
|
||||
return gguf.Verdict{Checked: true,
|
||||
Reason: "it is an importance matrix for quantising, not a model"}
|
||||
}
|
||||
if arch == "" || !gguf.IsGGUF(name) {
|
||||
return gguf.Verdict{Servable: true}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"html"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -114,3 +115,51 @@ func TestARepositoryShowsItsCard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestARepositoryOpensAsAFragmentBeneathItsRow(t *testing.T) {
|
||||
reg := &fakeRegistry{repo: hf.Repo{
|
||||
ID: "Qwen/X-GGUF", Revision: "abc123def456", Card: "A **small** model.",
|
||||
Files: []hf.File{{Path: "x.gguf", Bytes: 10}},
|
||||
}}
|
||||
rec := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror/repo?repo=Qwen/X-GGUF")
|
||||
body := rec.Body.String()
|
||||
if rec.Code != 200 {
|
||||
t.Fatalf("status %d: %s", rec.Code, body)
|
||||
}
|
||||
// The card and the fetch form, and not a page around them.
|
||||
for _, want := range []string{"<strong>small</strong>", `action="/admin/mirror/fetch"`, `name="csrf"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("missing %s: %s", want, body)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{"<html", "back to the list", "<h3>"} {
|
||||
if strings.Contains(body, unwanted) {
|
||||
t.Errorf("the fragment carries %s", unwanted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAFragmentForARegistryThatFailsSaysSo(t *testing.T) {
|
||||
reg := &fakeRegistry{err: errors.New("reaching the model registry: timeout")}
|
||||
rec := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror/repo?repo=Qwen/X-GGUF")
|
||||
if rec.Code != 502 || !strings.Contains(rec.Body.String(), "timeout") {
|
||||
t.Errorf("status %d: %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnImportanceMatrixIsNotOfferedAsAModel(t *testing.T) {
|
||||
reg := &fakeRegistry{repo: hf.Repo{
|
||||
ID: "a/X-GGUF", Revision: "abc123def456", Architecture: "qwen2",
|
||||
Files: []hf.File{{Path: "x-q4_k_m.gguf", Bytes: 10}, {Path: "imatrix-x.gguf", Bytes: 5}},
|
||||
}}
|
||||
body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
|
||||
"/admin/mirror/repo?repo=a/X-GGUF").Body.String()
|
||||
if !strings.Contains(body, "importance matrix") {
|
||||
t.Errorf("the imatrix should be marked as not a model: %s", body)
|
||||
}
|
||||
if strings.Count(body, `action="/admin/mirror/fetch"`) != 1 {
|
||||
t.Errorf("only the model should have a fetch form: %s", body)
|
||||
}
|
||||
}
|
||||
@@ -488,3 +488,21 @@ details.model-card .card-body { max-height: 28rem; overflow: auto; padding: 0 1r
|
||||
.card-body table { width: auto; max-width: 100%; display: block; overflow-x: auto; font-size: .8rem; }
|
||||
.card-body td, .card-body th { padding: .25rem .5rem; }
|
||||
.card-body a.img { font-size: .8rem; }
|
||||
/* A repository opened beneath its row in the listing. */
|
||||
table.explore tr.open > td { background: var(--bg); }
|
||||
table.explore a.open-repo::before { content: "▸ "; color: var(--muted); text-decoration: none; display: inline-block; width: 1em; }
|
||||
table.explore a.open-repo[aria-expanded="true"]::before { content: "▾ "; }
|
||||
table.explore tr.repo-detail > td { background: var(--bg); padding: .75rem 1rem 1rem; border-top: 0; }
|
||||
table.explore tr.repo-detail table { background: var(--card); }
|
||||
table.explore tr.repo-detail td:first-child { max-width: none; }
|
||||
/* A repository's files: name, version and button on one line, so a repository
|
||||
of a dozen quantisations is a dozen lines rather than a dozen boxes. */
|
||||
table.repo-files td { vertical-align: middle; }
|
||||
table.repo-files td:first-child { overflow-wrap: anywhere; }
|
||||
table.repo-files form.inline { display: flex; flex-wrap: nowrap; gap: .35rem; align-items: center; margin: 0; }
|
||||
table.repo-files form.inline input[type=text] { display: inline-block; width: auto; margin: 0; padding: .3rem .45rem; font-size: .8rem; }
|
||||
table.repo-files form.inline input[name=model] { width: 12rem; min-width: 0; flex: 1 1 12rem; }
|
||||
table.repo-files form.inline input[name=version] { width: 6.5rem; }
|
||||
table.repo-files form.inline button { padding: .3rem .7rem; font-size: .8rem; }
|
||||
table.repo-files td:last-child { width: 1%; white-space: nowrap; }
|
||||
table.repo-files td:last-child .opt { display: block; margin-bottom: .2rem; }
|
||||
@@ -214,8 +214,8 @@ document.addEventListener('click', function (e) {
|
||||
<table class="explore">
|
||||
<tr><th>Repository</th><th class="num">Size</th><th>Architecture</th><th class="num">Context</th>
|
||||
<th class="num">Downloads</th><th class="num">Likes</th><th class="num">Updated</th></tr>
|
||||
{{range .Rows}}<tr>
|
||||
<td><a href="{{.Href}}"><code>{{.ID}}</code></a>
|
||||
{{range .Rows}}<tr class="explore-row">
|
||||
<td><a href="{{.Href}}" class="open-repo" data-repo="{{.ID}}" aria-expanded="false"><code>{{.ID}}</code></a>
|
||||
{{if .New}}<span class="tag new">new</span>{{end}}{{if .Gated.Is}}<span class="tag">gated</span>{{end}}
|
||||
{{if or .BaseModel .License}}<div class="from">{{with .BaseModel}}from {{.}}{{end}}{{if and .BaseModel .License}} · {{end}}{{.License}}</div>{{end}}</td>
|
||||
<td class="num">{{.ParamsLabel}}</td>
|
||||
@@ -226,6 +226,44 @@ document.addEventListener('click', function (e) {
|
||||
<td class="num">{{.Age}}</td>
|
||||
</tr>{{end}}
|
||||
</table>
|
||||
<script>
|
||||
// A repository opens beneath its row rather than replacing the list: the
|
||||
// list is what somebody is choosing from, and losing it to read one card
|
||||
// means finding their place again for the next. The link still goes to the
|
||||
// repository's own page when this does not run, or with a modifier key.
|
||||
document.querySelector("table.explore").addEventListener("click", async function (e) {
|
||||
const a = e.target.closest("a.open-repo");
|
||||
if (!a || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
|
||||
e.preventDefault();
|
||||
const row = a.closest("tr");
|
||||
let detail = row.nextElementSibling;
|
||||
if (detail && detail.classList.contains("repo-detail")) {
|
||||
detail.hidden = !detail.hidden;
|
||||
a.setAttribute("aria-expanded", String(!detail.hidden));
|
||||
row.classList.toggle("open", !detail.hidden);
|
||||
return;
|
||||
}
|
||||
detail = document.createElement("tr");
|
||||
detail.className = "repo-detail";
|
||||
const td = document.createElement("td");
|
||||
td.colSpan = row.children.length;
|
||||
td.textContent = "Loading…";
|
||||
detail.appendChild(td);
|
||||
row.after(detail);
|
||||
row.classList.add("open");
|
||||
a.setAttribute("aria-expanded", "true");
|
||||
try {
|
||||
const resp = await fetch("/admin/mirror/repo?repo=" + encodeURIComponent(a.dataset.repo));
|
||||
const text = await resp.text();
|
||||
if (!resp.ok) { td.textContent = text.slice(0, 300); td.classList.add("error-row"); return; }
|
||||
// Our own server's rendering of the repository, the card already
|
||||
// stripped of anything that runs: the same HTML the full page shows.
|
||||
td.innerHTML = text;
|
||||
} catch (err) {
|
||||
td.textContent = "Could not load it: " + err;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{{if .Hidden}}<p class="note">{{.Hidden}} more {{if eq .Hidden 1}}is{{else}}are{{end}} hidden: their architecture is one the nodes' llama.cpp cannot load.
|
||||
Untick “only what these nodes can run” to see them.</p>{{end}}
|
||||
<p class="note">A gated repository needs its terms accepted with a Hugging Face
|
||||
@@ -237,10 +275,43 @@ directory, or give the mirror a token.</p>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
|
||||
{{if .Repo}}
|
||||
<p><a href="{{.Back}}">← back to the list</a></p>
|
||||
<h3>{{.Repo.ID}} <span class="opt">at {{.Repo.ShortRevision}}</span></h3>
|
||||
{{if .Repo}}{{template "mirror_repo" .}}{{end}}
|
||||
{{end}}
|
||||
|
||||
<h2>Fetch a model</h2>
|
||||
<p class="note">By hand, for anything the search does not reach.</p>
|
||||
<form method="post" action="/admin/mirror/fetch">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Source URL
|
||||
<input type="text" name="source" required
|
||||
placeholder="https://huggingface.co/…/resolve/main/model.gguf"></label>
|
||||
<div class="field-row">
|
||||
<label>Model <input type="text" name="model" required placeholder="qwen2.5-coder-7b"></label>
|
||||
<label>Version <input type="text" name="version" required placeholder="2026-09"></label>
|
||||
<label>File <span class="opt">optional</span>
|
||||
<input type="text" name="file" placeholder="taken from the URL"></label>
|
||||
</div>
|
||||
<label class="inline-check"><input type="checkbox" name="force" value="1">
|
||||
Fetch anyway <span class="opt">even if the nodes' llama.cpp cannot load it</span></label>
|
||||
<button type="submit">Start download</button>
|
||||
</form>
|
||||
<p class="note">The mirror answers as soon as the download is under way, not when
|
||||
it finishes — a model is tens of gigabytes and nothing here holds a connection
|
||||
open for that. The row above will show it arriving. A version is never
|
||||
overwritten: fetching into one that exists is refused, so a new build is a new
|
||||
version and the old weights stay where they are.</p>
|
||||
{{end}}
|
||||
|
||||
<footer><span>llmgw {{.Version}}</span><span>{{.Now}}</span></footer>
|
||||
</div></body></html>{{end}}
|
||||
|
||||
{{/* One repository: its card and its files. The whole page when opened by
|
||||
address, and the row beneath a listing entry when opened from the list. */}}
|
||||
{{define "mirror_repo"}}
|
||||
{{if not .Inline}}<p><a href="{{.Back}}">← back to the list</a></p>
|
||||
<h3>{{.Repo.ID}} <span class="opt">at {{.Repo.ShortRevision}}</span></h3>{{end}}
|
||||
<p class="repo-meta">
|
||||
{{if .Inline}}<span>at <code>{{.Repo.ShortRevision}}</code></span>{{end}}
|
||||
{{with .Repo.BaseModel}}<span>from {{range $i, $b := .}}{{if $i}}, {{end}}<code>{{$b}}</code>{{end}}</span>{{end}}
|
||||
{{with .Repo.License}}<span>license {{.}}</span>{{end}}
|
||||
{{with .Repo.Languages}}<span>{{join .}}</span>{{end}}
|
||||
@@ -253,8 +324,8 @@ directory, or give the mirror a token.</p>
|
||||
</details>
|
||||
{{end}}
|
||||
{{if .RepoSets}}
|
||||
<table>
|
||||
<tr><th>What</th><th>Size</th><th>Published checksum</th><th></th></tr>
|
||||
<table class="repo-files">
|
||||
<tr><th>What</th><th class="num">Size</th><th>Published checksum</th><th></th></tr>
|
||||
{{range .RepoSets}}<tr>
|
||||
<td><code>{{.Name}}</code>
|
||||
{{if .Shards}}<span class="opt">{{.Shards}} shards, fetched together</span>{{end}}</td>
|
||||
@@ -292,31 +363,3 @@ computes once it has it.</p>
|
||||
<p class="empty">No weight files in {{.Repo.ID}}.</p>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<h2>Fetch a model</h2>
|
||||
<p class="note">By hand, for anything the search does not reach.</p>
|
||||
<form method="post" action="/admin/mirror/fetch">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Source URL
|
||||
<input type="text" name="source" required
|
||||
placeholder="https://huggingface.co/…/resolve/main/model.gguf"></label>
|
||||
<div class="field-row">
|
||||
<label>Model <input type="text" name="model" required placeholder="qwen2.5-coder-7b"></label>
|
||||
<label>Version <input type="text" name="version" required placeholder="2026-09"></label>
|
||||
<label>File <span class="opt">optional</span>
|
||||
<input type="text" name="file" placeholder="taken from the URL"></label>
|
||||
</div>
|
||||
<label class="inline-check"><input type="checkbox" name="force" value="1">
|
||||
Fetch anyway <span class="opt">even if the nodes' llama.cpp cannot load it</span></label>
|
||||
<button type="submit">Start download</button>
|
||||
</form>
|
||||
<p class="note">The mirror answers as soon as the download is under way, not when
|
||||
it finishes — a model is tens of gigabytes and nothing here holds a connection
|
||||
open for that. The row above will show it arriving. A version is never
|
||||
overwritten: fetching into one that exists is refused, so a new build is a new
|
||||
version and the old weights stay where they are.</p>
|
||||
{{end}}
|
||||
|
||||
<footer><span>llmgw {{.Version}}</span><span>{{.Now}}</span></footer>
|
||||
</div></body></html>{{end}}
|
||||
Reference in new issue
Block a user