go/pkg/lab/collector/huggingface.go
Snider adaa4131f9 refactor: strip to pure package library (#3)
- Fix remaining 187 pkg/ files referencing core/cli → core/go
- Move SDK library code from internal/cmd/sdk/ → pkg/sdk/ (new package)
- Create pkg/rag/helpers.go with convenience functions from internal/cmd/rag/
- Fix pkg/mcp/tools_rag.go to use pkg/rag instead of internal/cmd/rag
- Fix pkg/build/buildcmd/cmd_sdk.go and pkg/release/sdk.go to use pkg/sdk
- Remove all non-library content: main.go, internal/, cmd/, docker/,
  scripts/, tasks/, tools/, .core/, .forgejo/, .woodpecker/, Taskfile.yml
- Run go mod tidy to trim unused dependencies

core/go is now a pure Go package suite (library only).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Co-authored-by: Claude <developers@lethean.io>
Reviewed-on: #3
2026-02-16 14:23:45 +00:00

55 lines
1.2 KiB
Go

package collector
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
"forge.lthn.ai/core/go/pkg/lab"
)
type HuggingFace struct {
author string
store *lab.Store
}
func NewHuggingFace(author string, s *lab.Store) *HuggingFace {
return &HuggingFace{author: author, store: s}
}
func (h *HuggingFace) Name() string { return "huggingface" }
func (h *HuggingFace) Collect(ctx context.Context) error {
u := fmt.Sprintf("https://huggingface.co/api/models?author=%s&sort=downloads&direction=-1&limit=20", h.author)
req, err := http.NewRequestWithContext(ctx, "GET", u, nil)
if err != nil {
return err
}
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
h.store.SetError("huggingface", err)
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err := fmt.Errorf("HuggingFace API returned %d", resp.StatusCode)
h.store.SetError("huggingface", err)
return err
}
var models []lab.HFModel
if err := json.NewDecoder(resp.Body).Decode(&models); err != nil {
h.store.SetError("huggingface", err)
return err
}
h.store.SetModels(models)
h.store.SetError("huggingface", nil)
return nil
}