-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (38 loc) · 1.09 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require('express');
const app = express();
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
app.use(express.static("views"));
app.get('/', (req, res) => {
res.sendFile(__dirname + "/views/index.html")
});
app.use(express.json());
app.post("/increment", (req, res) => {
const response = (async () => {
const message = req.body.message
try {
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: message}],
});
const ress = completion.data.choices[0].message
return ress
} catch (err) {
console.log(err);
}
})();
response.then((response) => {
res.json({ response: response });
});
});
app.post("/manage_data", (req, res) => {
console.log(req.body.message)
res.json({ response: response });
console.log(response)
});
app.listen(3000, () => {
console.log('Server is listening on port 3000');
});