@noisemakerjon/spam-classifier
v0.1.0
Published
LLM-based spam classifier for form submissions. Works with any OpenAI-compatible API.
Maintainers
Readme
spam-classifier
Simple LLM-based spam classifier for form submissions.
Install
npm install spam-classifierUsage
import { createClassifier } from "spam-classifier";
// Set up once
const isSpam = createClassifier({
apiKey: process.env.OPENROUTER_API_KEY!,
});
// Use anywhere - returns true/false
if (await isSpam("Need a quote for your services")) {
// spam - ignore it
}
// Or get details
const result = await isSpam.details("Need a quote");
// { isSpam: false, confidence: 0.95, reason: "Customer requesting quote" }Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | required | API key |
| model | string | "openai/gpt-4o-mini" | Model to use |
| baseUrl | string | OpenRouter | API endpoint |
| zdr | boolean | false | Enable Zero Data Retention |
Providers
Works with any OpenAI-compatible API:
// OpenRouter (default)
const isSpam = createClassifier({ apiKey: process.env.OPENROUTER_API_KEY! });
// OpenAI directly
const isSpam = createClassifier({
apiKey: process.env.OPENAI_API_KEY!,
baseUrl: "https://api.openai.com/v1/chat/completions",
model: "gpt-4o-mini",
});
// Local LLM
const isSpam = createClassifier({
apiKey: "not-needed",
baseUrl: "http://localhost:11434/v1/chat/completions",
model: "llama3",
});Fail-Safe
Returns false (legitimate) if the API fails, so you never block real customers.
Cost
~$0.0002 per classification. 10,000 submissions = ~$2.
License
MIT
