-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (23 loc) · 922 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require('express');
const bodyParser = require('body-parser');
const { GPT3 } = require('gpt-3');
const app = express();
const PORT = process.env.PORT || 3000;
// Инициализация API GPT
const gpt3 = new GPT3({ apiKey: 'sk-32323-29SWBUEQyj1Jx9346eG4T3BlbkFJOXxLTCXjZCoQlOQvrxVZ' });
app.use(bodyParser.json());
// Обработка запроса от клиента
app.post('/sendMessage', async (req, res) => {
const userMessage = req.body.message;
try {
// Генерация ответа с помощью API GPT
const botResponse = await gpt3.send(userMessage);
res.json({ message: botResponse });
} catch (error) {
console.error('Error generating response:', error);
res.status(500).json({ message: 'Internal Server Error' });
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});