Package Exports
- zerolabel
- zerolabel/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zerolabel) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
zerolabel
Zero-shot multimodal classification SDK. Classify text and images with custom labelsβno training required. Powered by Google Gemma 3-27B under the hood.
Features
β¨ Zero-shot classification: No training data needed, just provide your labels
π Multimodal support: Classify text, images, or both together
β‘ Fast & reliable: Built-in retry logic and error handling
π― High accuracy: Powered by Google Gemma 3-27B
π¦ TypeScript-first: Full type safety and IntelliSense support
π Simple API: Easy to integrate, minimal setup required
Installation
npm install zerolabelQuick Start
import { classify } from 'zerolabel';
// Classify text
const results = await classify({
texts: ['I love this product!'],
labels: ['positive', 'negative', 'neutral'],
inference_api_key: process.env.INFERENCE_API_KEY
});
console.log(results[0].predicted_label); // 'positive'
console.log(results[0].confidence); // 85.3Authentication
Get your API key from inference.net or contact us for access.
Usage Examples
Text Classification
import { classify } from 'zerolabel';
const results = await classify({
texts: [
'The movie was amazing!',
'I hate this service.',
'It was okay, nothing special.'
],
labels: ['positive', 'negative', 'neutral'],
inference_api_key: process.env.INFERENCE_API_KEY
});
results.forEach((result, i) => {
console.log(`Text ${i + 1}: ${result.predicted_label} (${result.confidence}%)`);
});Image Classification
import { classify } from 'zerolabel';
import fs from 'fs';
// Convert image to base64
const imageBuffer = fs.readFileSync('path/to/image.jpg');
const imageBase64 = `data:image/jpeg;base64,${imageBuffer.toString('base64')}`;
const results = await classify({
images: [imageBase64],
labels: ['cat', 'dog', 'bird', 'other'],
inference_api_key: process.env.INFERENCE_API_KEY
});
console.log(`Image contains: ${results[0].predicted_label}`);Multimodal Classification (Text + Image)
const results = await classify({
texts: ['Check out this cute animal!'],
images: [imageBase64],
labels: ['cute cat', 'cute dog', 'not cute', 'not animal'],
inference_api_key: process.env.INFERENCE_API_KEY
});Custom Criteria and Instructions
const results = await classify({
texts: ['The AI model performed well on most tasks.'],
labels: ['technical', 'non-technical'],
criteria: 'Focus on the complexity and technical depth of the content',
additionalInstructions: 'Consider industry jargon and technical terminology',
inference_api_key: process.env.INFERENCE_API_KEY
});Batch Processing
const results = await classify({
texts: [
'Great customer service!',
'Product arrived damaged.',
'Fast delivery, good packaging.',
'Hard to contact support.'
],
labels: ['service_issue', 'product_issue', 'delivery_issue', 'positive'],
inference_api_key: process.env.INFERENCE_API_KEY
});
// Process results
results.forEach((result, i) => {
console.log(`Review ${i + 1}: ${result.predicted_label}`);
console.log(`Confidence: ${result.confidence}%`);
console.log(`Probabilities:`, result.probabilities);
console.log('---');
});API Reference
ZeroLabelClient
Constructor
new ZeroLabelClient(config: ZeroLabelConfig)Parameters:
config.inference_api_key(string, required): Your inference.net API keyconfig.maxRetries(number, optional): Max retry attempts (default: 3)
Note: All requests are proxied through inference.net - no custom endpoints or models allowed.
Methods
classify(input, options?)
Classify text and/or images against provided labels.
classify(input: ClassificationInput, options?: ClassificationOptions): Promise<ClassificationResult[]>Parameters:
input.texts(string[], optional): Texts to classifyinput.images(string[], optional): Images as base64 data URIsinput.labels(string[], required): Classification labelsinput.criteria(string, optional): Additional evaluation criteriainput.additionalInstructions(string, optional): Extra instructions for the model
Returns: Promise<ClassificationResult[]>
ClassificationResult
interface ClassificationResult {
text: string; // Original input text
predicted_label: string; // Predicted label
confidence: number; // Confidence score (0-100)
probabilities: Record<string, number>; // Probability distribution
logprobs: Record<string, number | null>; // Log probabilities
all_logprobs: Record<string, number>; // All token log probabilities
prompt: string; // Generated prompt
}Convenience Functions
Quick Classification
For simple use cases, use the classify function:
import { classify } from 'zerolabel';
const results = await classify({
inference_api_key: 'your-inference-api-key',
texts: ['Amazing product!'],
labels: ['positive', 'negative']
});Client Factory
import { createClient } from 'zerolabel';
const client = createClient({
inference_api_key: 'your-inference-api-key',
maxRetries: 5
});Error Handling
The SDK throws ZeroLabelError for various error conditions:
import { ZeroLabelError } from 'zerolabel';
try {
const results = await client.classify({
texts: ['Hello world'],
labels: [] // Empty labels will throw an error
});
} catch (error) {
if (error instanceof ZeroLabelError) {
console.error(`Error: ${error.message}`);
console.error(`Code: ${error.code}`);
console.error(`Status: ${error.statusCode}`);
}
}Configuration
Environment Variables
You can set your API key using environment variables:
export INFERENCE_API_KEY="your-inference-api-key"const client = new ZeroLabelClient({
inference_api_key: process.env.INFERENCE_API_KEY!
});Custom Configuration
const client = new ZeroLabelClient({
inference_api_key: 'your-inference-api-key',
maxRetries: 5
});Note: baseUrl and model are not configurable - all requests go through inference.net.
TypeScript Support
The SDK is built with TypeScript and provides full type safety:
import type {
ZeroLabelConfig,
ClassificationInput,
ClassificationResult,
ClassificationOptions
} from 'zerolabel';
// All types are available for import
const config: ZeroLabelConfig = {
inference_api_key: 'your-inference-api-key'
};Best Practices
- Reuse client instances for better performance
- Use descriptive labels for better accuracy
- Batch multiple inputs when possible
- Handle errors gracefully with try-catch blocks
- Set appropriate retry limits based on your use case
Support
- π Issues
- π§ Email Support
License
MIT License - see LICENSE file for details.