-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (35 loc) · 1.23 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
require('dotenv').config();
const PORT = process.env.PORT;
const express = require('express');
const cors = require('cors');
const fetch = require("node-fetch");
const app = express();
app.use(express.json());
app.use(cors());
const API_KEY = process.env.OPENAI_API_KEY;
const API_URL = 'https://api.openai.com/v1/chat/completions';
// api routes
app.post('/resumeWork', async(req, res) => {
const question = "Generate a list of common job interview questions and suggested answers using the STAR (Situation, Task, Action, Result) format. Tailor the responses based on my work experience - " + req.body.message;
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: question}],
max_tokens: 1000,
})
};
try {
const response = await fetch(API_URL, options);
const data = await response.json();
res.send(data);
} catch (error) {
console.log(error);
}
});
// setup server listener
app.listen(PORT, () => console.log('Server is running on port ' + PORT))