-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathapp.js
44 lines (38 loc) · 1.12 KB
/
app.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const express = require('express');
const axios = require('axios');
const path = require('path');
const app = express();
const port = 1234;
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
async function query(data) {
const response = await fetch(
"http://localhost:3000/api/v1/prediction/7ab03e5c-d5c0-4cfc-bfa5-7cd1c3a4e12d",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}
);
const result = await response.json();
return result;
}
app.post('/getChatResponse', async (req, res) => {
const { userInput } = req.body;
try {
query({"question": userInput}).then((responseData) => {
res.send({ response: responseData.text });
});
} catch (error) {
console.error('Error:', error.message);
res.status(500).send('An error occurred');
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});