Skip to content

feat(classifier): NanoGPT-backed category-classify fetcher (32-axis taxonomy) - #3185

Open
0motionguy wants to merge 1 commit into
mainfrom
feat/classify-categories-nanogpt-v2
Open

0motionguy wants to merge 1 commit into
mainfrom
feat/classify-categories-nanogpt-v2

Conversation

@0motionguy

Copy link
Copy Markdown
Owner

Summary

Without a classifier, the 17 new chips shipped in C-CAT PR #3174 read "0 repos." This PR wires the missing piece: a daily NanoGPT-backed classifier that maps every consensus-trending repo into one of the 32 category ids.

Approach

  • New fetcher apps/trendingrepo-worker/src/fetchers/category-classify/ — reads consensus-trending payload, batches the top-1000 fullNames into chunks of 20, sends each chunk to NanoGPT (Kimi-K2-Instruct via OpenAI-compatible chat) with strict response_format: { type: 'json_object' } and the full 32-id taxonomy embedded in the system prompt.
  • Re-classification skip rule — any repo whose previous classification is fresher than 7 days is skipped. Bounds cost as the pool grows.
  • Schedule'17 3 * * *' UTC, well off the on-the-hour peaks where the other fetchers run.
  • Cost discipline — ~$0.00003/call × (1000 / 20-per-batch) = $0.0015/day at full pool. Documented in code.
  • No publicly stale batches rule — payload emits computedAt + staleness_seconds so UI consumers can drop the category facet when stale.

Companion PRs

  • #3174 C-CAT — ships the 32 taxonomy entries
  • #3181 per-category-landing-pages — renders /categories/<slug> with JSON-LD
  • This PR — the classifier that ties them together so each chip lights up with real repos

Files

apps/trendingrepo-worker/src/fetchers/category-classify/
├── index.ts        — fetcher (batched LLM sweep, skip-fresh, write payload)
├── llm.ts          — NanoGPT primary + Kimi fallback (lifted from L1 PR #3172 pattern)
├── types.ts        — CategoryClassifyPayload, VALID_CATEGORY_IDS, CATEGORY_BRIEFS
└── __tests__/types.test.ts — 4 vitest tests asserting taxonomy schema
apps/trendingrepo-worker/src/lib/env.ts — NANOGPT_API_KEY/_BASE_URL/_MODEL + widen LLM_PROVIDER enum
apps/trendingrepo-worker/src/lib/llm/router.ts — narrows the wider enum back to 'kimi'|'openrouter' for the unrelated router
apps/trendingrepo-worker/src/registry.ts — register categoryClassify in FETCHERS
scripts/classify-categories.ts — one-shot seed script for post-deploy

Test plan

  • pnpm --filter trendingrepo-worker tsc --noEmit — clean
  • pnpm --filter trendingrepo-worker test src/fetchers/category-classify — 4/4 pass
  • Operator sets NANOGPT_API_KEY and runs pnpm tsx scripts/classify-categories.ts once — verify ss:data:v1:repo-categories populates with assignments
  • Verify per-category landing page (feat(seo): JSON-LD CollectionPage + schema graph for /categories/[slug] #3181) reads the assignments and lights up the new C-CAT chips

Evidence

Deep-crawl deltas v3: OSSInsight ships 102 curated collections to TrendingRepo's 15; C-CAT brought us to 32; this classifier makes those 32 actually useful. Toolbox PR #241 has the underlying delta.

🤖 Generated with Claude Code

…axonomy)

Without this fetcher, the 17 new categories shipped in C-CAT PR #3174
read "0 repos." Wires a daily classifier that maps every consensus-
trending repo into one of the 32 ids (15 existing + 17 new from C-CAT).

Approach:
- New fetcher apps/trendingrepo-worker/src/fetchers/category-classify/
  reads consensus-trending payload, batches the top-1000 fullNames into
  chunks of 20, sends each chunk to NanoGPT (Kimi-K2-Instruct) with a
  strict response_format json_object and the full 32-id taxonomy embedded
  in the system prompt.
- Re-classifies any repo whose previous classification is older than 7
  days; skips fresh assignments to keep cost bounded.
- Emits ss:data:v1:repo-categories with computedAt + staleness_seconds
  so UI consumers can drop the chip facet when stale (no publicly stale
  batches rule).
- Schedule: '17 3 * * *' UTC (well off the on-the-hour peaks where other
  fetchers run).
- Cost discipline: ~$0.00003 per NanoGPT call × (1000 repos / 20-per-
  batch) = $0.0015/day at full pool. Documented in fetcher.

NanoGPT client (apps/trendingrepo-worker/src/fetchers/category-classify/
llm.ts) lifts the L1 PR #3172 dual-provider pattern: NanoGPT primary when
NANOGPT_API_KEY is set, Kimi fallback otherwise.

env.ts: add NANOGPT_API_KEY/_BASE_URL/_MODEL and widen LLM_PROVIDER enum
to include 'nanogpt'. llm/router.ts narrows back to its own
'kimi'|'openrouter' (it doesn't serve nanogpt; the classifier has its
own client).

scripts/classify-categories.ts: one-shot seed for operators to run after
deploy without waiting for the cron tick.

Vitest: 4 tests asserting the taxonomy schema (32 entries, no dupes,
description coverage, chunk size sanity).

Companion PRs in the ULTRA plan: C-CAT #3174 ships the taxonomy; this
PR ships the classifier; #3181 per-category-landing-pages renders them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0motionguy added a commit that referenced this pull request Jun 15, 2026
Closes part of the v3 deep-crawl deltas finding that no competitor has any
API/RSS/webhook surface (defensibility 3.0). 32 categories × 1 RSS feed
gives 32 SEO + agent-readable surfaces; the per-category llms.txt section
makes the feeds discoverable to AI agents that follow the convention.

Files:
- src/app/feeds/[slug].xml/route.ts (new) — dynamic [slug] = one of the 32
  category ids from src/lib/constants.ts. Returns RSS 2.0 XML with
  proper content-type + Cache-Control: s-maxage=900, swr=3600. Falls back
  to an "indexing in progress" item when the classifier (PR #3185) hasn't
  populated repo-categories yet.
- src/app/feeds/route.ts (new) — index page listing all 32 feed URLs as
  JSON for agent discovery.
- src/app/llms.txt/route.ts (modified) — adds "Per-category RSS feeds"
  section generated from CATEGORIES so the file scales when the taxonomy
  changes again.
- src/app/categories/[slug]/page.tsx (modified) — adds
  <link rel="alternate" type="application/rss+xml"> so feed readers can
  auto-discover the matching feed.
- src/lib/pipeline/__tests__/feeds-routes.test.ts — RSS XML escaping (&, <, >),
  content-type, and at-least-one <item> shape assertions.
- scripts/check-production-topology-docs.mjs — adds a llms.txt topology
  phrase requirement so the HOSTUP section stays accurate.

No publicly stale batches: when consensus-trending is past 4h, the feed
emits an "indexing in progress" item instead of stale items.

Companion PRs: C-CAT #3174 (taxonomy), classify #3185 (per-repo
assignments), per-category-pages #3181 (HTML landing), Toolbox #241
(ULTRA harness with the deltas evidence).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant