Skip to content

feat: NVIDIA NIM LLM-guided analysis - #2

Merged
nitrimandylis merged 1 commit into
mainfrom
feat/nim-llm-analysis
Jun 24, 2026
Merged

feat: NVIDIA NIM LLM-guided analysis#2
nitrimandylis merged 1 commit into
mainfrom
feat/nim-llm-analysis

Conversation

@nitrimandylis

Copy link
Copy Markdown
Owner

Summary

Adds opt-in LLM-guided cost analysis powered by NVIDIA NIM as an alternative to the hardcoded rule engines. When enabled, an NIM-hosted model reasons over usage instead of fixed thresholds; when off, the existing rule engine runs unchanged.

What's included

  • lib/nim/ — vendor-agnostic LLM analysis: analysis rules + system prompt, adapters from Anthropic/OpenAI rows to a neutral summary, and deterministic guardrails in mergeLlmFindings that keep a weak model honest:
    • savings clamped to a row's spend, and cumulative savings per row capped at spend (no >100%)
    • at most one model downgrade per row (no contradictory Sonnet + Haiku)
    • reject "downgrades" whose target tier isn't actually cheaper (no upgrade-as-savings)
    • drop zero-savings cost findings as noise
  • /api/nim proxy — key read from server env NIM_API_KEY (never sent to the browser); NIM_MODEL override; NIM_MOCK offline mode; upstream timeout so slow models fail fast; GET reports whether NIM is configured.
  • UI — persisted "Use AI analysis (NVIDIA NIM)" toggle, shown only when the server reports NIM is configured.
  • storage — evict oldest analysis on localStorage quota errors.

Config (deployment)

  • NIM_API_KEY=nvapi-... — enables the feature
  • NIM_MODEL=... — optional model override (use a valid catalog id)
  • NIM_MOCK=1 — optional offline mode for local testing

Testing

  • Unit tests for guardrails, merge/grounding logic, and quota eviction
  • npm run type-check, npm run lint, and vitest all pass (46 tests)

🤖 Generated with Claude Code

Add opt-in LLM-driven cost analysis powered by NVIDIA NIM, alongside the
existing hardcoded rule engines.

- lib/nim: vendor-agnostic LLM analysis (rules + system prompt), adapters
  from Anthropic/OpenAI rows, and deterministic guardrails in
  mergeLlmFindings (savings clamped to spend, one downgrade per row, no
  upgrade-as-downgrade, drop zero-savings noise) so a weak model can't emit
  contradictory or impossible advice.
- /api/nim proxy: key from server env (NIM_API_KEY), NIM_MODEL override,
  NIM_MOCK offline mode, request timeout, GET reports availability.
- UI: persisted "Use AI analysis (NVIDIA NIM)" toggle, shown only when the
  server reports NIM configured. Key never touches the browser.
- storage: evict oldest analysis on localStorage quota errors.
- tests for guardrails, merge logic, and quota eviction.

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

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tokenpilot Ready Ready Preview, Comment Jun 24, 2026 1:20pm

@nitrimandylis
nitrimandylis merged commit 2ab87b3 into main Jun 24, 2026
3 checks passed
@nitrimandylis
nitrimandylis deleted the feat/nim-llm-analysis branch June 24, 2026 13:20
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