-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 loc) · 1.47 KB
/
index.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
import { Configuration, OpenAIApi } from "openai";
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
const configuration = new Configuration({
organization: "org-SUPl1gSLK3tF1F32a78Daixm",
apiKey: "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",
});
const openai = new OpenAIApi(configuration);
const app = express();
app.use(bodyParser.json());
app.use(cors());
// console.log(openai);
// app.get("/", async (req, res) => {
// const completion = await openai.createChatCompletion({
// model: "gpt-3.5-turbo",
// messages: [{ role: "user", content: "Hello world" }],
// });
// res.json({ completion: completion.data.choices[0].message });
// // console.log(completeion.data);
// });
app.post("/", async (req, res) => {
console.log(req);
const { messages } = req.body;
console.log(messages);
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: "You are sportsGpt for sports fan" },
...messages,
],
});
res.json({ completion: completion.data.choices[0].message });
// console.log(completeion.data);
});
const PORT = 9000;
app.listen(PORT, () => {
console.log(`App is listening in ${PORT}`);
});
// const completion = await openai.createChatCompletion({
// model: "gpt-3.5-turbo",
// messages: [{ role: "system", content: "You are a graphics designer" }],
// });
// console.log(completion.data.choices[0].message);