Comprehend-it
Zero-shot and few-shot text classification with confidence scores using the Knowledgator TypeScript SDK.
Example Usage
import { createClient } from '@knowledgator/typescript-sdk';
const kg = createClient();
const result = await kg.comprehend.it({
text: "I love this product! It exceeded my expectations.",
tasks: {
sentiment: {
type: "classify",
labels: ["positive", "negative", "neutral"],
threshold: 0.5,
},
},
adapter_id: "your-lora-adapter-id", // Optional LoRA adapter
});
console.log(result.outputs.sentiment);
LoRA Adapters vs. Open Models
adapter_id is for fine-tuned LoRA adapters attached to the base Comprehend-it service. If you trained a standalone Open Model (e.g. GLiClass or GLiNER checkpoint), query it via kg.model(model_id).predict(...) instead.
Expected Output
{
"positive": 0.942,
"neutral": 0.045,
"negative": 0.013
}
Result Object Structure
result.outputs provides structured outputs for each configured task:
// Accessing scores programmatically
const task = result.outputs.sentiment;
if (task.scores) {
for (const [label, score] of Object.entries(task.scores)) {
console.log(`${label}: ${(score as number).toFixed(3)}`);
}
}