// Installation: npm install openai
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
async function generateText(prompt: string) {
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
});
return completion.choices[0].message.content;
}
// Example usage:
const response = await generateText("What is the capital of France?");
console.log(response);