Getting started with AI in Node.js is simpler than you might think. The key libraries to know are:
1. OpenAI SDK
npm install openai
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const completion = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});
console.log(completion.choices[0].message.content);
2. LangChain.js
For more complex chains and agents:
npm install langchain
3. Hugging Face Transformers
For local model inference:
npm install @huggingface/inference
These three libraries cover 90% of AI use cases in Node.js applications.
