Hugging Face in the console: models that chat when browsing, ages read at a glance, long menus scroll
CI / test (push) Successful in 6m1s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-03 23:47:26 +02:00
1 parent 2bf43ed90c
commit a96b1a54b2
2 files changed
+44 -3

No files matched your search

+14 -1
View File
@@ -244,13 +244,26 @@ func (m consoleModel) actionDialog() (title, body string) {
return m.confirmD.title, m.confirmD.text + "\n\n" + sDim.Render("Y yes · any other key no")
case m.menuD != nil:
var b strings.Builder
for i, it := range m.menuD.items {
// A long menu shows the part around the choice.
items, first := m.menuD.items, 0
if room := max(5, m.height-12); len(items) > room {
first = min(max(0, m.menuD.sel-room/2), len(items)-room)
items = items[first : first+room]
if first > 0 {
b.WriteString(sDim.Render(" ↑ more") + "\n")
}
}
for j, it := range items {
i := first + j
if i == m.menuD.sel {
b.WriteString(fSelected.Render("› "+it.label) + "\n")
} else {
b.WriteString(" " + it.label + "\n")
}
}
if first+len(items) < len(m.menuD.items) {
b.WriteString(sDim.Render(" ↓ more") + "\n")
}
b.WriteString("\n" + sDim.Render("↑↓ choose · Enter · Esc close"))
return m.menuD.title, b.String()
}
+30 -2
View File
@@ -60,7 +60,13 @@ func (m consoleModel) fetchHF() tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
defer cancel()
got, err := c.Explore(ctx, hf.Query{Search: q, Sort: hfSorts[sort].sort, GGUF: true, Limit: 50})
hq := hf.Query{Search: q, Sort: hfSorts[sort].sort, GGUF: true, Limit: 50}
// Browsing: models that chat. A search finds the rest too, an
// embedding model included.
if q == "" {
hq.Task = "text-generation"
}
got, err := c.Explore(ctx, hq)
return consoleHFMsg{query: q, sort: sort, models: got, err: err}
}
}
@@ -164,6 +170,9 @@ func (m consoleModel) hfPanel(pw int) (string, string, string) {
if m.hf.query != "" {
what = "“" + m.hf.query + "”, " + what
}
if m.hf.query == "" {
what = "text generation, " + what
}
head := "\n GGUF models on Hugging Face: " + what + "\n\n"
switch {
case m.hf.err != nil:
@@ -183,7 +192,7 @@ func (m consoleModel) hfPanel(pw int) (string, string, string) {
gated = sWarn.Render("gated")
}
rows = append(rows, []string{x.ID, params, x.Architecture(), compactNum(x.Downloads), compactNum(x.Likes),
ago(x.LastModified, time.Now()), gated})
ageShort(x.LastModified), gated})
}
if len(rows) == 0 {
return "Serve from Hugging Face", head + " " + sDim.Render("Nothing found. / searches again."), keys
@@ -191,3 +200,22 @@ func (m consoleModel) hfPanel(pw int) (string, string, string) {
return "Serve from Hugging Face", head + table([]string{"REPOSITORY", "SIZE", "ARCH", "DOWNLOADS", "LIKES", "UPDATED", ""},
rows, m.row, pw, m.inPanel), keys
}
// ageShort is how long ago, in the largest unit that says it: 5m, 3h, 12d, 7mo, 2y.
func ageShort(t time.Time) string {
if t.IsZero() {
return ""
}
d := time.Since(t)
switch {
case d < time.Hour:
return fmt.Sprintf("%dm ago", int(d.Minutes()))
case d < 48*time.Hour:
return fmt.Sprintf("%dh ago", int(d.Hours()))
case d < 60*24*time.Hour:
return fmt.Sprintf("%dd ago", int(d.Hours()/24))
case d < 2*365*24*time.Hour:
return fmt.Sprintf("%dmo ago", int(d.Hours()/24/30))
}
return fmt.Sprintf("%dy ago", int(d.Hours()/24/365))
}