-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (29 loc) · 853 Bytes
/
server.js
File metadata and controls
33 lines (29 loc) · 853 Bytes
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
const P0RT = 8000;
const express = require("express");
const cors = require("cors");
const app = express();
app.use(express.json());
app.use(cors());
const API_KEY = "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";
app.post("/completions", async (req, res) => {
const options = {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: req.body.message}],
max_tokens: 100,
}),
};
try {
const response = await fetch("https://api.openai.com/v1/chat/completions", options)
const data = await response.json()
res.send(data)
} catch (error) {
console.error(error);
}
});
app.listen(P0RT, () => console.log(`Server running on port ${P0RT}`));