NodeJs — Integrating AI with Node.js
You can integrate AI into your Node.js apps by connecting with AI APIs such as OpenAI, Hugging Face, or TensorFlow.js. This allows you to add features like natural language processing, sentiment analysis, and image recognition.
npm install openai
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function runAI() {
const response = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello, AI!' }],
});
console.log(response.data.choices[0].message.content);
}
runAI();