大模型
dev.to ·
@Ram Chandra Giri
我从教育科技平台中抽离并开源了 3 个小型 Node 工具
作者在构建尼泊尔 NEB 课程备考平台 MCQplex 时,将三块与考试业务无关的基础设施抽成独立开源包。llm-free-cascade 把 Gemini、Groq、Cerebras 等免费额度 LLM API 级联起来,在多个 key 间自动轮换,并对结构性故障的 provider 设置冷却,零依赖;pdf-render-pool 则针对 Puppeteer 每次新建 headless Chromium 约 1-2 秒、约 200MB 内存的开销做进程池化。文章为个人项目介绍,未给出基准测试或使用数据。
AI推荐理由 开发者从尼泊尔 NEB 备考平台 MCQplex 中抽离并开源三个 Node 工具,其中 llm-free-cascade 将 Gemini、Groq、Cerebras 等免费额度 LLM API 做级联故障转移与多 key 轮换,并支持对结构性故障的 provider 冷却,零依赖;pdf-render-pool 针对 Puppeteer 每次启动 headless Chromium 的 1-2 秒与约 200MB 内存开销做池化。属具体可复用的工程实现,但为个人项目,未提供性能基准或采用情况。
66
正文
I've spent the last while building MCQplex, an exam-prep
platform for Nepal's NEB curriculum. Along the way I built a few pieces of
infrastructure that had nothing to do with exams specifically, so I pulled
them out into their own packages:
llm-free-cascade
Free-tier LLM APIs (Gemini, Groq, Cerebras, and others) are individually
rate-limited, but between them they add up to a lot of free inference if you
just fail over from one to the next. This cascades a chat completion across
however many you've got keys for, with automatic multi-key rotation (if
you've made more than one free account on a provider) and cooldown for a
provider that's structurally broken. Zero dependencies.
const { LLMCascade } = require('llm-free-cascade');
const cascade = LLMCascade.fromEnv();
const { text, provider } = await cascade.generate({ system, user });
Enter fullscreen mode
Exit fullscreen mode
pdf-render-pool
Launching a fresh headless Chromium per PDF (the naive way to use Puppeteer)
costs 1-2 seconds and ~200MB of RAM every time. This keeps one browser warm
and gives each render its own page, with a concurrency cap so a burst of PDF
requests queues instead of taking the server down.
mongo-job-lock
If you run node-cron jobs on more than one instance (PM2 cluster, several
servers), every instance fires the job unless you do something about it.
This is a tiny MongoDB-backed advisory lock — steal-on-expiry, so a crashed
holder can't deadlock the job forever — for whatever Mongo connection you
already have.
All three: zero or optional-peer dependencies, MIT licensed, tested, on npm.
Feedback / PRs welcome, especially on llm-free-cascade since free-tier
model names drift constantly and providers.json is set up so a one-file PR
fixes a stale one.