typescriptbeginner

Text Classification

AI/ML technique: text-classification

typescript
import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const resp = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [
    { role: "system", content: "Return one label: positive, neutral, or negative" },
    { role: "user", content: "The onboarding was fast and smooth" },
  ],
  temperature: 0,
});

console.log(resp.choices[0].message.content);

Use Cases

  • machine learning
  • AI applications

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.