From 02fa639657488973a25aea4d8fee4e520e6ab925 Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Mon, 28 Sep 2026 21:56:58 +0200 Subject: [PATCH] Open the mirror's registry on what is current, not an empty search box The mirror page lists Hugging Face's trending models without anything typed, with views for what is new this month and what is most downloaded, filters for task and size, and each repository's parameter count, architecture, context length and age from one registry call. "Only what these nodes can run" is on by default and leaves out architectures the nodes' llama.cpp cannot load, and adapters, saying how many it hid. Listings are remembered for ten minutes. The stylesheet is now linked by a hash of its content. It is cached for a day, so under a fixed name a deploy's new styles reached people a day after its markup. Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/hf/hf.go | 135 ++++++++++++- internal/hf/hf_test.go | 43 ++++ internal/web/admin_mirror.go | 19 +- internal/web/admin_mirror_test.go | 6 +- internal/web/mirror_explore.go | 241 +++++++++++++++++++++++ internal/web/mirror_explore_test.go | 99 ++++++++++ internal/web/static/base.css | 22 ++- internal/web/templates/account.html | 6 +- internal/web/templates/admin_mirror.html | 49 +++-- internal/web/templates/admin_quotas.html | 2 +- internal/web/templates/admin_usage.html | 2 +- internal/web/templates/admin_users.html | 2 +- internal/web/templates/chat.html | 2 +- internal/web/templates/claim.html | 2 +- internal/web/templates/dashboard.html | 2 +- internal/web/templates/landing.html | 2 +- internal/web/templates/node_logs.html | 2 +- internal/web/templates/org.html | 4 +- internal/web/web.go | 20 +- internal/web/web_test.go | 24 +++ 20 files changed, 632 insertions(+), 52 deletions(-) create mode 100644 internal/web/mirror_explore.go create mode 100644 internal/web/mirror_explore_test.go diff --git a/internal/hf/hf.go b/internal/hf/hf.go index d274cdd..9892584 100644 --- a/internal/hf/hf.go +++ b/internal/hf/hf.go @@ -19,6 +19,7 @@ import ( "net/url" "regexp" "strings" + "sync" "time" ) @@ -29,6 +30,9 @@ const DefaultEndpoint = "https://huggingface.co" type Client struct { base string hc *http.Client + + mu sync.Mutex + cache map[string]cached } // New builds a client against an endpoint, or the public one when empty. @@ -58,6 +62,36 @@ type Model struct { // it is not a plain bool here. Gated Gated `json:"gated"` Private bool `json:"private"` + + CreatedAt time.Time `json:"createdAt"` + TrendingScore float64 `json:"trendingScore"` + // GGUF is what the registry read from the repository's weights, absent + // for one that has none. + GGUF *GGUFInfo `json:"gguf"` +} + +// GGUFInfo is the registry's summary of a repository's GGUF weights. +type GGUFInfo struct { + // Total is the parameter count. + Total int64 `json:"total"` + Architecture string `json:"architecture"` + ContextLength int64 `json:"context_length"` +} + +// Params is the parameter count, 0 when the registry does not know it. +func (m Model) Params() int64 { + if m.GGUF == nil { + return 0 + } + return m.GGUF.Total +} + +// Architecture is the GGUF architecture, empty when unknown. +func (m Model) Architecture() string { + if m.GGUF == nil { + return "" + } + return m.GGUF.Architecture } // Gated is Hugging Face's gating flag, which is false or a word. @@ -92,20 +126,101 @@ func (c *Client) Search(ctx context.Context, query string, limit int) ([]Model, if strings.TrimSpace(query) == "" { return nil, fmt.Errorf("search for something") } - if limit <= 0 || limit > 50 { - limit = 20 + // By downloads, because the thing somebody means by a short name is + // almost always the one everybody else meant too. + return c.Explore(ctx, Query{Search: query, Sort: SortDownloads, Limit: limit}) +} + +// Sort orders an exploration. +type Sort string + +// The orders the registry offers that are worth offering. +const ( + SortTrending Sort = "trendingScore" + SortDownloads Sort = "downloads" + SortLikes Sort = "likes" + SortCreated Sort = "createdAt" +) + +// Query is what to list from the registry. +type Query struct { + Search string + Sort Sort + // Task is a pipeline tag: text-generation, feature-extraction. Empty is + // any. + Task string + // GGUF keeps to repositories with GGUF weights, which is what llama.cpp + // loads. + GGUF bool + // MaxParams bounds the parameter count; 0 is no bound. The registry + // applies it, so a page of small models is a full page. + MaxParams int64 + Limit int +} + +// exploreFields is everything a listing shows. Asking for any field with +// expand returns only the fields asked for, so all of them are named. +var exploreFields = []string{"downloads", "likes", "pipeline_tag", "tags", "lastModified", + "createdAt", "gated", "private", "trendingScore", "gguf"} + +// Explore lists repositories: the trending ones, the newest, or a search. +// +// Remembered for a few minutes. The mirror page opens on this, and a page +// that waits on a registry on the far side of the internet every time it is +// opened is slow for news that changes by the hour. +func (c *Client) Explore(ctx context.Context, q Query) ([]Model, error) { + if q.Limit <= 0 || q.Limit > 100 { + q.Limit = 20 } - q := url.Values{ - "search": {query}, - "limit": {fmt.Sprint(limit)}, - // By downloads, because the thing somebody means by a short name is - // almost always the one everybody else meant too. - "sort": {"downloads"}, + if q.Sort == "" { + q.Sort = SortTrending + } + v := url.Values{ + "limit": {fmt.Sprint(q.Limit)}, + "sort": {string(q.Sort)}, "direction": {"-1"}, + "expand[]": exploreFields, } + if s := strings.TrimSpace(q.Search); s != "" { + v.Set("search", s) + } + if q.Task != "" { + v.Set("pipeline_tag", q.Task) + } + if q.GGUF { + v.Set("filter", "gguf") + } + if q.MaxParams > 0 { + v.Set("num_parameters", fmt.Sprintf("min:0,max:%d", q.MaxParams)) + } + path := "/api/models?" + v.Encode() + + c.mu.Lock() + if e, ok := c.cache[path]; ok && time.Since(e.at) < exploreTTL { + c.mu.Unlock() + return e.models, nil + } + c.mu.Unlock() + var out []Model - err := c.get(ctx, "/api/models?"+q.Encode(), &out) - return out, err + if err := c.get(ctx, path, &out); err != nil { + return nil, err + } + c.mu.Lock() + if c.cache == nil || len(c.cache) > 200 { + c.cache = map[string]cached{} + } + c.cache[path] = cached{at: time.Now(), models: out} + c.mu.Unlock() + return out, nil +} + +// exploreTTL is how long a listing is reused. +const exploreTTL = 10 * time.Minute + +type cached struct { + at time.Time + models []Model } // File is one file in a repository. diff --git a/internal/hf/hf_test.go b/internal/hf/hf_test.go index 8a8c904..e8c9db9 100644 --- a/internal/hf/hf_test.go +++ b/internal/hf/hf_test.go @@ -3,6 +3,8 @@ package hf import ( "net/http" "net/http/httptest" + "net/url" + "slices" "strings" "testing" "time" @@ -187,3 +189,44 @@ func TestAShardSetPublishesNoSingleChecksum(t *testing.T) { t.Errorf("expected no checksum for a set, got %q", got) } } + +func TestExploringAsksForWhatThePageFilters(t *testing.T) { + var got url.Values + calls := 0 + c := registry(t, func(w http.ResponseWriter, r *http.Request) { + calls++ + got = r.URL.Query() + _, _ = w.Write([]byte(`[{"id":"a/b-GGUF","gguf":{"total":7615616512,"architecture":"qwen2","context_length":32768}}]`)) + }) + + q := Query{Sort: SortTrending, Task: "text-generation", GGUF: true, MaxParams: 9e9, Limit: 30} + models, err := c.Explore(t.Context(), q) + if err != nil { + t.Fatal(err) + } + for k, want := range map[string]string{ + "sort": "trendingScore", "pipeline_tag": "text-generation", "filter": "gguf", + "num_parameters": "min:0,max:9000000000", "limit": "30", + } { + if got.Get(k) != want { + t.Errorf("%s = %q, want %q", k, got.Get(k), want) + } + } + // Expanding any field returns only the expanded ones, so the listing has + // to name the counts it shows as well as the GGUF summary. + if !slices.Contains(got["expand[]"], "gguf") || !slices.Contains(got["expand[]"], "downloads") { + t.Errorf("expand = %v", got["expand[]"]) + } + if len(models) != 1 || models[0].Params() != 7615616512 || models[0].Architecture() != "qwen2" { + t.Errorf("the GGUF summary did not decode: %+v", models) + } + + // The page opens on this; a second look within minutes is not a second + // trip to the registry. + if _, err := c.Explore(t.Context(), q); err != nil { + t.Fatal(err) + } + if calls != 1 { + t.Errorf("the registry was asked %d times", calls) + } +} diff --git a/internal/web/admin_mirror.go b/internal/web/admin_mirror.go index 41926b6..f6078f5 100644 --- a/internal/web/admin_mirror.go +++ b/internal/web/admin_mirror.go @@ -6,6 +6,7 @@ import ( "fmt" "gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog" "gitea.mynodes.xyz/ilker/llmgw/internal/gguf" + "html/template" "net/http" "sort" "strconv" @@ -36,7 +37,7 @@ type MirrorAdmin interface { // off, which is right for a deployment with no way out to the internet: a // search box that can only time out is worse than no search box. type Registry interface { - Search(ctx context.Context, query string, limit int) ([]hf.Model, error) + Explore(ctx context.Context, q hf.Query) ([]hf.Model, error) Repo(ctx context.Context, id string) (hf.Repo, error) } @@ -119,7 +120,9 @@ type adminMirrorData struct { // The explorer. HasRegistry bool Query string - Results []hf.Model + Explore *explorer + // Back is the listing an open repository was reached from. + Back template.URL Repo *hf.Repo RepoSets []repoSet RegistryErr string @@ -442,7 +445,7 @@ func plural(n int, one, many string) string { return strconv.Itoa(n) + " " + many } -// explore fills in the registry half of the page: a search, or one repository. +// explore fills in the registry half of the page: a listing, or one repository. // // A failure here is reported in its own line rather than as the page's error. // The registry is somebody else's server on the other side of the internet, and @@ -456,6 +459,7 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) { d.Query = strings.TrimSpace(r.URL.Query().Get("q")) 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() @@ -491,14 +495,7 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) { return } - if d.Query != "" { - got, err := p.registry.Search(r.Context(), d.Query, 20) - if err != nil { - d.RegistryErr = err.Error() - return - } - d.Results = got - } + p.exploreList(r, d) } // defaultModelName is the catalog name a repository suggests. diff --git a/internal/web/admin_mirror_test.go b/internal/web/admin_mirror_test.go index 3b0f5b0..2962fa8 100644 --- a/internal/web/admin_mirror_test.go +++ b/internal/web/admin_mirror_test.go @@ -345,10 +345,12 @@ type fakeRegistry struct { repo hf.Repo err error asked string + query hf.Query } -func (f *fakeRegistry) Search(_ context.Context, q string, _ int) ([]hf.Model, error) { - f.asked = q +func (f *fakeRegistry) Explore(_ context.Context, q hf.Query) ([]hf.Model, error) { + f.asked = q.Search + f.query = q return f.results, f.err } diff --git a/internal/web/mirror_explore.go b/internal/web/mirror_explore.go new file mode 100644 index 0000000..f66091d --- /dev/null +++ b/internal/web/mirror_explore.go @@ -0,0 +1,241 @@ +package web + +import ( + "fmt" + "html/template" + "net/http" + "net/url" + "strings" + "time" + + "gitea.mynodes.xyz/ilker/llmgw/internal/gguf" + "gitea.mynodes.xyz/ilker/llmgw/internal/hf" +) + +// The explorer's views: what the registry is excited about this week, what +// arrived this month, and what everybody settled on. +const ( + viewTrending = "trending" + viewNew = "new" + viewDownloads = "downloads" +) + +// newWithin is how recent a repository has to be to count as new. +const newWithin = 30 * 24 * time.Hour + +// minParams is the smallest thing worth calling a model. +const minParams = 50e6 + +// exploreShown is how many rows the explorer lists. +const exploreShown = 25 + +var exploreViews = []struct{ key, label string }{ + {viewTrending, "Trending"}, {viewNew, "New this month"}, {viewDownloads, "Most downloaded"}, +} + +var exploreTasks = []struct{ key, label, tag string }{ + {"chat", "Chat", "text-generation"}, {"embed", "Embeddings", "feature-extraction"}, {"any", "Any task", ""}, +} + +var exploreSizes = []struct { + key, label string + max int64 +}{ + {"3", "≤ 3B", 3e9}, {"9", "≤ 9B", 9e9}, {"35", "≤ 35B", 35e9}, {"any", "Any size", 0}, +} + +// explorer is the registry half of the mirror page when no repository is +// open: a listing, its filters, and links that keep them. +type explorer struct { + View, Task, Size string + // Here keeps to what the nodes' llama.cpp can load. On by default: a + // trending list is mostly things this cluster cannot run, and finding + // that out one repository at a time is what the explorer is for avoiding. + Here bool + Rows []exploreRow + // Hidden is how many rows Here took out, so an empty page says why. + Hidden int + + Views, Tasks, Sizes []exploreLink +} + +type exploreLink struct { + Label string + Href template.URL + Active bool +} + +type exploreRow struct { + hf.Model + Verdict gguf.Verdict + Href template.URL + New bool +} + +// ParamsLabel is the parameter count as people say it: 7.6B, 494M. +func (r exploreRow) ParamsLabel() string { + n := r.Params() + switch { + case n <= 0: + return "—" + case n >= 1e9: + return trimZero(fmt.Sprintf("%.1f", float64(n)/1e9)) + "B" + default: + return fmt.Sprintf("%dM", n/1e6) + } +} + +// ContextLabel is the context length in thousands of tokens. +func (r exploreRow) ContextLabel() string { + if r.GGUF == nil || r.GGUF.ContextLength <= 0 { + return "—" + } + return fmt.Sprintf("%dk", r.GGUF.ContextLength/1024) +} + +// Age is how long ago the repository last changed, coarsely. +func (r exploreRow) Age() string { + t := r.LastModified + if t.IsZero() { + t = r.CreatedAt + } + if t.IsZero() { + return "—" + } + d := time.Since(t) + switch { + case d < time.Hour: + return "just now" + case d < 48*time.Hour: + return fmt.Sprintf("%dh", int(d.Hours())) + case d < 14*24*time.Hour: + return fmt.Sprintf("%dd", int(d.Hours()/24)) + case d < 60*24*time.Hour: + return fmt.Sprintf("%dw", int(d.Hours()/24/7)) + default: + return fmt.Sprintf("%dmo", int(d.Hours()/24/30)) + } +} + +func trimZero(s string) string { return strings.TrimSuffix(s, ".0") } + +// exploreState reads the explorer's settings from the address. With none set +// — the page opened from the menu — it is trending chat models this cluster +// can run. +func exploreState(q url.Values) explorer { + e := explorer{View: q.Get("view"), Task: q.Get("task"), Size: q.Get("size")} + // "x" marks a submitted form, so an unticked box reads as off rather than + // as not yet chosen. + e.Here = q.Get("x") != "1" || q.Get("here") == "1" + if !oneOf(e.View, viewTrending, viewNew, viewDownloads) { + e.View = viewTrending + // A search with no view asks for what a name usually means, which is + // the one everybody downloads. + if strings.TrimSpace(q.Get("q")) != "" { + e.View = viewDownloads + } + } + if !oneOf(e.Task, "chat", "embed", "any") { + e.Task = "chat" + } + if !oneOf(e.Size, "3", "9", "35", "any") { + e.Size = "any" + } + return e +} + +func oneOf(s string, options ...string) bool { + for _, o := range options { + if s == o { + return true + } + } + return false +} + +// href is the page with these settings and one of them changed. +func (e explorer) href(query, key, value string) template.URL { + v := url.Values{"view": {e.View}, "task": {e.Task}, "size": {e.Size}, "x": {"1"}} + if e.Here { + v.Set("here", "1") + } + if query != "" { + v.Set("q", query) + } + if key != "" { + v.Set(key, value) + } + return template.URL("/admin/mirror?" + v.Encode()) +} + +// hfQuery is what to ask the registry for. +func (e explorer) hfQuery(search string) hf.Query { + q := hf.Query{Search: search, Sort: hf.SortTrending, Limit: 60, + // What runs here is GGUF; the architecture check needs the registry's + // reading of one. + GGUF: e.Here} + switch e.View { + case viewDownloads: + q.Sort = hf.SortDownloads + case viewNew: + // Trending, then kept to the recent: sorted by creation date alone, + // the newest repositories are mostly empty uploads nobody has used. + q.Limit = 100 + } + for _, t := range exploreTasks { + if t.key == e.Task { + q.Task = t.tag + } + } + for _, s := range exploreSizes { + if s.key == e.Size { + q.MaxParams = s.max + } + } + return q +} + +// exploreList fills in the listing. +func (p *AccountPages) exploreList(r *http.Request, d *adminMirrorData) { + e := exploreState(r.URL.Query()) + for _, v := range exploreViews { + e.Views = append(e.Views, exploreLink{v.label, e.href(d.Query, "view", v.key), v.key == e.View}) + } + for _, t := range exploreTasks { + e.Tasks = append(e.Tasks, exploreLink{t.label, e.href(d.Query, "task", t.key), t.key == e.Task}) + } + for _, s := range exploreSizes { + e.Sizes = append(e.Sizes, exploreLink{s.label, e.href(d.Query, "size", s.key), s.key == e.Size}) + } + d.Explore = &e + + got, err := p.registry.Explore(r.Context(), e.hfQuery(d.Query)) + if err != nil { + d.RegistryErr = err.Error() + return + } + back := e.href(d.Query, "", "") + for _, m := range got { + if e.View == viewNew && time.Since(m.CreatedAt) > newWithin { + continue + } + row := exploreRow{Model: m, Verdict: gguf.Verdict{Servable: true}, + Href: back + template.URL("&repo="+url.QueryEscape(m.ID)), + New: !m.CreatedAt.IsZero() && time.Since(m.CreatedAt) < newWithin} + if a := m.Architecture(); a != "" && p.llamaVersion != "" { + row.Verdict = gguf.LlamaCpp(p.llamaVersion, a) + } + // An adapter or a fragment, not a model: tens of megabytes of LoRA + // weights listed among the models they need a model to run on. + if e.Here && m.Params() > 0 && m.Params() < minParams { + continue + } + if e.Here && row.Verdict.Checked && !row.Verdict.Servable { + e.Hidden++ + continue + } + if len(e.Rows) < exploreShown { + e.Rows = append(e.Rows, row) + } + } +} diff --git a/internal/web/mirror_explore_test.go b/internal/web/mirror_explore_test.go new file mode 100644 index 0000000..bfc6346 --- /dev/null +++ b/internal/web/mirror_explore_test.go @@ -0,0 +1,99 @@ +package web + +import ( + "html" + "strings" + "testing" + "time" + + "gitea.mynodes.xyz/ilker/llmgw/internal/hf" +) + +func ggufModel(id, arch string, params int64, created time.Time) hf.Model { + return hf.Model{ID: id, CreatedAt: created, LastModified: created, + GGUF: &hf.GGUFInfo{Total: params, Architecture: arch, ContextLength: 32768}} +} + +func TestTheExplorerOpensOnTrendingModelsTheNodesCanRun(t *testing.T) { + // Opened from the menu, with nothing typed: what is current, in the + // shape this cluster runs, without a search to start it. + now := time.Now() + reg := &fakeRegistry{results: []hf.Model{ + ggufModel("Qwen/Qwen3-8B-GGUF", "qwen3", 8.2e9, now.Add(-90*24*time.Hour)), + ggufModel("odd/Kev-GGUF", "ggmlc", 5e8, now.Add(-2*24*time.Hour)), + }} + body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror").Body.String() + + q := reg.query + if q.Sort != hf.SortTrending || q.Task != "text-generation" || !q.GGUF || q.Search != "" { + t.Errorf("asked the registry for %+v", q) + } + if !strings.Contains(body, "Qwen/Qwen3-8B-GGUF") || !strings.Contains(body, "8.2B") { + t.Errorf("the trending model is missing or unsized: %s", body) + } + // The kev case: listed, it invites a fetch the nodes cannot use. + if strings.Contains(body, "odd/Kev-GGUF") { + t.Error("a model llama.cpp cannot load is offered") + } + if !strings.Contains(body, "1 more is hidden") { + t.Error("the page should say something was hidden, and why") + } +} + +func TestUntickingRunsHereShowsEverythingWithAVerdict(t *testing.T) { + reg := &fakeRegistry{results: []hf.Model{ + ggufModel("odd/Kev-GGUF", "ggmlc", 5e8, time.Now()), + }} + // x=1 is the submitted form; "here" absent is the box unticked. + body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror?x=1&view=downloads&task=any&size=9").Body.String() + + q := reg.query + if q.GGUF || q.Sort != hf.SortDownloads || q.Task != "" || q.MaxParams != 9e9 { + t.Errorf("asked the registry for %+v", q) + } + if !strings.Contains(body, "odd/Kev-GGUF") || !strings.Contains(body, "ggmlc ✗") { + t.Errorf("the unrunnable model should be listed and marked: %s", body) + } +} + +func TestNewThisMonthLeavesOutOlderRepositories(t *testing.T) { + now := time.Now() + reg := &fakeRegistry{results: []hf.Model{ + ggufModel("a/Old-GGUF", "llama", 1e9, now.Add(-200*24*time.Hour)), + ggufModel("a/Fresh-GGUF", "llama", 1e9, now.Add(-3*24*time.Hour)), + }} + body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror?view=new").Body.String() + if strings.Contains(body, "a/Old-GGUF") || !strings.Contains(body, "a/Fresh-GGUF") { + t.Errorf("new this month shows the wrong repositories: %s", body) + } +} + +func TestOpeningARepositoryKeepsTheWayBack(t *testing.T) { + reg := &fakeRegistry{results: []hf.Model{ggufModel("a/B-GGUF", "llama", 1e9, time.Now())}} + mux := mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}) + body := html.UnescapeString(mirrorGet(t, mux, "/admin/mirror?view=new&size=3").Body.String()) + if !strings.Contains(body, "size=3") || !strings.Contains(body, "repo=a%2FB-GGUF") { + t.Fatalf("the row's link should keep the filters: %s", body) + } + + reg.repo = hf.Repo{ID: "a/B-GGUF", Revision: "abc123def456"} + body = html.UnescapeString(mirrorGet(t, mux, "/admin/mirror?view=new&size=3&repo=a/B-GGUF").Body.String()) + if !strings.Contains(body, "back to the list") || !strings.Contains(body, "view=new") { + t.Errorf("the repository page should lead back to the same listing: %s", body) + } +} + +func TestAnAdapterIsNotListedAsAModel(t *testing.T) { + reg := &fakeRegistry{results: []hf.Model{ + ggufModel("a/Some-LoRA-GGUF", "qwen2", 2e6, time.Now()), + ggufModel("a/Tiny-GGUF", "qwen2", 135e6, time.Now()), + }} + body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}), + "/admin/mirror").Body.String() + if strings.Contains(body, "Some-LoRA") || !strings.Contains(body, "a/Tiny-GGUF") { + t.Errorf("adapters should be left out and small models kept: %s", body) + } +} diff --git a/internal/web/static/base.css b/internal/web/static/base.css index 59ff2ee..347ad70 100644 --- a/internal/web/static/base.css +++ b/internal/web/static/base.css @@ -60,7 +60,7 @@ li { margin: .25rem 0; } a { color: var(--accent); } .wrap.narrow { max-width: 30rem; } label { display: block; margin: .9rem 0; font-size: .9rem; font-weight: 600; } -input[type=text], input[type=email], input[type=password] { +input[type=text], input[type=email], input[type=password], input[type=search] { display: block; width: 100%; margin-top: .3rem; font: inherit; font-weight: 400; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); @@ -456,3 +456,23 @@ table.held .use .as { display: block; font-size: .72rem; color: var(--muted); table.held .use .opt { font-size: .75rem; line-height: 1.3; } table.held td.num { white-space: nowrap; } table.held select.mode { width: 100%; padding: .15rem .3rem; font-size: .8rem; } + +/* Link pills: the same look as .tabs, for choices that are addresses rather + than panels on one page — a filtered listing should survive a reload and be + worth sending to somebody. */ +.pills { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; } +.pills a { font-size: .85rem; font-weight: 600; color: var(--muted); padding: .35rem .85rem; + border: 1px solid transparent; border-radius: 999px; text-decoration: none; } +.pills a:hover { color: var(--fg); } +.pills a.on { color: var(--fg); background: var(--card); border-color: var(--line); } +.pills.small a { font-size: .78rem; font-weight: 500; padding: .2rem .65rem; } +.explore-filters { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; } +.explore-search { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; margin: .5rem 0 .75rem; } +.explore-search input[type=search] { flex: 1 1 18rem; width: auto; margin: 0; } +.explore-search label.check { font-size: .85rem; color: var(--muted); display: inline-flex; gap: .35rem; align-items: center; margin: 0; } +table.explore td:first-child { max-width: 28rem; overflow-wrap: anywhere; } +table.explore td.num { white-space: nowrap; } +table.explore .cannot { color: var(--bad); } +.tag { display: inline-block; font-size: .7rem; font-weight: 600; color: var(--muted); + border: 1px solid var(--line); border-radius: 999px; padding: 0 .4rem; margin-left: .3rem; vertical-align: 1px; } +.tag.new { color: var(--accent); border-color: var(--accent); } diff --git a/internal/web/templates/account.html b/internal/web/templates/account.html index 97a2390..c1a599a 100644 --- a/internal/web/templates/account.html +++ b/internal/web/templates/account.html @@ -1,7 +1,7 @@ {{define "signup"}} -Sign up · llmgw +Sign up · llmgw

Create an account

An operator approves it before it can be used.

@@ -30,7 +30,7 @@ Tell whoever you asked for access that you have signed up.

{{define "login"}} -Sign in · llmgw +Sign in · llmgw

Sign in

@@ -47,7 +47,7 @@ Tell whoever you asked for access that you have signed up.

{{define "profile"}} -Your keys · llmgw +Your keys · llmgw

Your keys

diff --git a/internal/web/templates/admin_mirror.html b/internal/web/templates/admin_mirror.html index b54392b..de32b44 100644 --- a/internal/web/templates/admin_mirror.html +++ b/internal/web/templates/admin_mirror.html @@ -4,7 +4,7 @@ {{/* Only while something is downloading. A reload at any other time would take with it whatever the operator was typing into the form below. */}} {{if .RefreshSec}}{{end}} -Mirror · llmgw +Mirror · llmgw

Model mirror

@@ -183,12 +183,24 @@ document.addEventListener('click', function (e) { {{else}}

The mirror is reachable and holds nothing yet.

{{end}} {{if .HasRegistry}} -

Find a model

-
- +

Explore models

+{{if not .Repo}}{{with .Explore}} + +
+ + +
+{{end}} + + {{with .Explore}} + + + {{end}} + +
+{{end}} {{if .RegistryErr}} {{/* Its own line, not the page's error: the registry is somebody else's server @@ -197,24 +209,35 @@ document.addEventListener('click', function (e) {

The registry: {{.RegistryErr}}

{{end}} -{{if .Results}} - -{{range .Results}} - +{{if not .Repo}}{{with .Explore}} +{{if .Rows}} +
RepositoryDownloadsTask
{{.ID}}{{if .Gated.Is}} gated{{end}}
+ + +{{range .Rows}} + + + + - - + + {{end}}
RepositorySizeArchitectureContextDownloadsLikesUpdated
{{.ID}} + {{if .New}}new{{end}}{{if .Gated.Is}}gated{{end}}{{.ParamsLabel}}{{if .Architecture}}{{.Architecture}}{{if .Verdict.Checked}}{{if .Verdict.Servable}} ✓{{else}} ✗{{end}}{{end}}{{else}}—{{end}}{{.ContextLabel}} {{compact .Downloads}}{{or .PipelineTag "—"}}files{{compact .Likes}}{{.Age}}
+{{if .Hidden}}

{{.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.

{{end}}

A gated repository needs its terms accepted with a Hugging Face account, and this browses anonymously — the files will list, and fetching one will fail at the mirror. Download it by hand and put it in the mirror directory, or give the mirror a token.

-{{else if .Query}}{{if not .RegistryErr}} -

Nothing matched “{{.Query}}”.

+{{else if not $.RegistryErr}} +

{{if $.Query}}Nothing matched “{{$.Query}}”{{else}}Nothing to list{{end}}{{if .Hidden}} that these nodes can run — {{.Hidden}} {{if eq .Hidden 1}}result was{{else}}results were{{end}} hidden for an architecture llama.cpp cannot load{{end}}.

+{{end}} {{end}}{{end}} {{if .Repo}} +

← back to the list

{{.Repo.ID}} at {{.Repo.ShortRevision}}

{{if .RepoSets}} diff --git a/internal/web/templates/admin_quotas.html b/internal/web/templates/admin_quotas.html index 646dede..41404e5 100644 --- a/internal/web/templates/admin_quotas.html +++ b/internal/web/templates/admin_quotas.html @@ -1,7 +1,7 @@ {{define "admin_quotas"}} -Quotas · llmgw +Quotas · llmgw {{/* Links and forms work as plain navigation; htmx, when it loads, swaps only #quotas so opening a form or saving one does not jump the page. */}} diff --git a/internal/web/templates/admin_usage.html b/internal/web/templates/admin_usage.html index 9aaaa25..ff5c29a 100644 --- a/internal/web/templates/admin_usage.html +++ b/internal/web/templates/admin_usage.html @@ -1,7 +1,7 @@ {{define "admin_usage"}} -Usage · llmgw +Usage · llmgw

Usage over time

diff --git a/internal/web/templates/admin_users.html b/internal/web/templates/admin_users.html index 9372bb4..3738ac4 100644 --- a/internal/web/templates/admin_users.html +++ b/internal/web/templates/admin_users.html @@ -1,7 +1,7 @@ {{define "admin_users"}} -People · llmgw +People · llmgw {{/* Forms here post and get the whole page back, which works with no script at all. htmx, when it loads, swaps only #people from that page instead of reloading it, so an open project stays open and the page does not jump. */}} diff --git a/internal/web/templates/chat.html b/internal/web/templates/chat.html index b448f05..642530b 100644 --- a/internal/web/templates/chat.html +++ b/internal/web/templates/chat.html @@ -1,7 +1,7 @@ {{define "chat"}} -Chat · llmgw +Chat · llmgw diff --git a/internal/web/templates/claim.html b/internal/web/templates/claim.html index e88fce3..59de474 100644 --- a/internal/web/templates/claim.html +++ b/internal/web/templates/claim.html @@ -2,7 +2,7 @@ -Your llmgw key +Your llmgw key

Your API key

diff --git a/internal/web/templates/dashboard.html b/internal/web/templates/dashboard.html index e2b55af..59a68de 100644 --- a/internal/web/templates/dashboard.html +++ b/internal/web/templates/dashboard.html @@ -2,7 +2,7 @@ -llmgw — cluster +llmgw — cluster

Cluster

diff --git a/internal/web/templates/landing.html b/internal/web/templates/landing.html index 6afb79b..1450d02 100644 --- a/internal/web/templates/landing.html +++ b/internal/web/templates/landing.html @@ -3,7 +3,7 @@ llmgw - +
{{if .Notice}}{{end}} diff --git a/internal/web/templates/node_logs.html b/internal/web/templates/node_logs.html index deb926f..4b21a83 100644 --- a/internal/web/templates/node_logs.html +++ b/internal/web/templates/node_logs.html @@ -2,7 +2,7 @@ {{if .Follow}}{{end}} -llmgw — {{.Node}} logs +llmgw — {{.Node}} logs

{{.Node}}

diff --git a/internal/web/templates/org.html b/internal/web/templates/org.html index cfaf5f4..5e62e09 100644 --- a/internal/web/templates/org.html +++ b/internal/web/templates/org.html @@ -1,7 +1,7 @@ {{define "org"}} -{{.Org.Name}} · llmgw +{{.Org.Name}} · llmgw

{{.Org.Name}}

@@ -96,7 +96,7 @@ people do elsewhere — in another organization, or on their own — is not show {{define "org-none"}} -Organizations · llmgw +Organizations · llmgw

Organizations

diff --git a/internal/web/web.go b/internal/web/web.go index ea67337..a143c30 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -14,7 +14,9 @@ package web import ( + "crypto/sha256" "embed" + "encoding/hex" "fmt" "html/template" "io/fs" @@ -35,9 +37,23 @@ var files embed.FS //go:embed static var staticFiles embed.FS +// stylesheetURL names the stylesheet by its content. The assets are cached for a +// day, and under a fixed name a deploy that changed the page's look reached +// people a day later — or reached the markup at once and the styles not at +// all, which is worse than either. +var stylesheetURL = func() string { + b, err := staticFiles.ReadFile("static/base.css") + if err != nil { + panic("web: the stylesheet is missing from the binary: " + err.Error()) + } + sum := sha256.Sum256(b) + return "/_static/base.css?v=" + hex.EncodeToString(sum[:4]) +}() + var funcs = template.FuncMap{ - "lower": strings.ToLower, - "sub": func(a, b int) int { return a - b }, + "stylesheet": func() string { return stylesheetURL }, + "lower": strings.ToLower, + "sub": func(a, b int) int { return a - b }, "join": func(v []string) string { if len(v) == 0 { return "—" diff --git a/internal/web/web_test.go b/internal/web/web_test.go index 2883bb3..7d76b25 100644 --- a/internal/web/web_test.go +++ b/internal/web/web_test.go @@ -2,7 +2,10 @@ package web import ( "context" + "crypto/sha256" + "encoding/hex" "errors" + "html/template" "net/http" "net/http/httptest" "strings" @@ -602,3 +605,24 @@ func TestTheLandingPageDiagramDescribesItself(t *testing.T) { t.Error("the schematic is decoration to anyone not looking at it") } } + +func TestTheStylesheetIsNamedByItsContent(t *testing.T) { + // Cached for a day: under a fixed name, a deploy's new styles reached + // people a day after its markup did. + b, err := staticFiles.ReadFile("static/base.css") + if err != nil { + t.Fatal(err) + } + sum := sha256.Sum256(b) + want := "/_static/base.css?v=" + hex.EncodeToString(sum[:4]) + if stylesheetURL != want { + t.Errorf("stylesheet at %q, want %q", stylesheetURL, want) + } + var out strings.Builder + if err := template.Must(template.New("").Funcs(funcs).Parse(``)).Execute(&out, nil); err != nil { + t.Fatal(err) + } + if !strings.Contains(out.String(), "v="+hex.EncodeToString(sum[:4])) { + t.Errorf("rendered as %s", out.String()) + } +}