zerolabel
Version:
Zero-shot multimodal classification SDK - classify text and images with custom labels, no training required
97 lines (92 loc) • 2.86 kB
text/typescript
/**
* Result of a single classification
*/
interface ClassificationResult {
/** Original text that was classified */
text: string;
/** The predicted label */
predicted_label: string;
/** Confidence score (0-100) */
confidence: number;
/** Probability distribution over all labels (0-100 scale) */
probabilities: Record<string, number>;
/** Log probabilities for each label (raw values) */
logprobs: Record<string, number | null>;
/** All log probabilities from the model response */
all_logprobs: Record<string, number>;
/** The prompt that was sent to the model */
prompt: string;
}
/**
* Error thrown by the SDK
*/
declare class ZeroLabelError extends Error {
readonly code?: string | undefined;
readonly statusCode?: number | undefined;
constructor(message: string, code?: string | undefined, statusCode?: number | undefined);
}
/**
* ZeroLabel SDK - Zero-shot multimodal classification
*
* Classify text and images with custom labels, no training required.
* Powered by Google Gemma 3-27B under the hood.
*
* @example
* ```typescript
* import { classify } from '@zerolabel/sdk';
*
* const results = await classify({
* texts: ['I love this product!'],
* labels: ['positive', 'negative', 'neutral'],
* apiKey: process.env.apiKey
* });
*
* console.log(results[0].predicted_label); // 'positive'
* ```
*/
interface ClassifyInput {
/** Array of texts to classify (optional if using images) */
texts?: string[];
/** Array of images as base64 data URIs (optional if using text) */
images?: string[];
/** Array of possible classification labels */
labels: string[];
/** Your Inference.net API key */
apiKey: string;
/** Optional additional criteria for classification */
criteria?: string;
/** Optional additional instructions for the model */
additionalInstructions?: string;
}
/**
* Classify text and/or images with custom labels.
*
* @example
* ```typescript
* import { classify } from '@zerolabel/sdk';
*
* // Text classification
* const results = await classify({
* texts: ['Amazing product!'],
* labels: ['positive', 'negative', 'neutral'],
* apiKey: process.env.apiKey
* });
*
* // Image classification
* const results = await classify({
* images: ['data:image/jpeg;base64,...'],
* labels: ['cat', 'dog', 'bird'],
* apiKey: process.env.apiKey
* });
*
* // Multimodal classification
* const results = await classify({
* texts: ['Check out this cute animal!'],
* images: ['data:image/jpeg;base64,...'],
* labels: ['cute cat', 'cute dog', 'not cute'],
* apiKey: process.env.apiKey
* });
* ```
*/
declare const classify: (input: ClassifyInput) => Promise<ClassificationResult[]>;
export { type ClassificationResult, type ClassifyInput, ZeroLabelError, classify };