-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathgpt-data.js
More file actions
29 lines (26 loc) · 915 Bytes
/
gpt-data.js
File metadata and controls
29 lines (26 loc) · 915 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
require('dotenv').config()
let bearerToken = process.env.OPEN_AI_KEY;
const getBlogData = async (req, response, content) => {
console.log(response)
return await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Authorization" : "Bearer " + bearerToken,
"Content-Type": "application/json"
},
body: JSON.stringify({
"model": "gpt-3.5-turbo-0613",
"messages": [{"role": "user", "content": content}],
"temperature": 0.7
})
}).then(async chatCompletionResponse => {
let res = await chatCompletionResponse.json();
response.send({"response": res.choices[0].message.content});
}).catch((err)=>{
response.send("error", err)
})
}
module.exports = { getBlogData }