import OpenAI from 'openai';
import * as weave from 'weave';
const openai = new OpenAI();
async function extractDinos(input) {
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{
role: 'user',
content: `Extract dinosaurs from this text. Return JSON with name, common_name, and diet: ${input}`,
},
],
});
return response.choices[0].message.content;
}
const extractDinosOp = weave.op(extractDinos);
async function main() {
await weave.init('examples');
const result = await extractDinosOp(
'I saw a T. rex chase a Triceratops. The T. rex eats meat. The Triceratops eats plants. A Brachiosaurus ate leaves from tall trees nearby.'
);
console.log(result);
}
main();