require('dotenv').config(); const express = require('express'); const { InferenceClient } = require('@huggingface/inference'); const app = express(); const port = 3000; const client = new InferenceClient(process.env.HF_TOKEN); app.use(express.json()); app.use(express.static('public')); app.post('/chat', async (req, res) => { try { const messages = req.body.messages; const chatCompletion = await client.chatCompletion({ provider: "hf-inference", model: "facebook/blenderbot-400M-distill", messages: messages, }); const response = chatCompletion.choices[0].message; res.json({ response }); } catch (error) { console.error(error); res.status(500).json({ error: 'An error occurred while processing your request.' }); } }); app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); });