import { Nua } from 'nuabase';
import { z } from 'zod';
// Initialize with your API Key
const nua = new Nua({ apiKey: 'YOUR_NUABASE_API_KEY' });
// Define the output schema
const SentimentSchema = z.object({
sentiment: z.enum(['Positive', 'Neutral', 'Negative']),
confidence: z.number().min(0).max(1),
});
// Create the LLM function
const analyzeSentiment = nua.createFn({
prompt: "Analyze the sentiment of the following text.",
output: {
name: "sentimentAnalysis",
schema: SentimentSchema,
},
});
async function main() {
const text = "The product is great, but the shipping was delayed.";
console.log("Analyzing...");
const result = await analyzeSentiment(text);
if (result.isSuccess) {
console.log("Result:", result.data);
} else {
console.error("Error:", result.error);
}
}
main();