-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatGpt.js
45 lines (45 loc) · 1.21 KB
/
chatGpt.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
const { Configuration, OpenAIApi } = require("openai");
require("dotenv").config();
async function callGpt(
topic,
slideNum = 6,
bulletMin = 3,
bulletMax = 5,
extra = "",
temperature = 0.2,
max_tokens = 500
) {
const configuration = new Configuration({
apiKey: process.env.API_KEY,
});
const openai = new OpenAIApi(configuration);
let prompt = `
create a power point script on ${topic},response should be in a JSON format similar to the following:
{
"title": "powerPointTitle",
"slides": [
{
"title": "titleName",
"content": [
"string","string","string",...
]
},
...}
Must be ${slideNum} slides long and each content array should have ${bulletMin}-${bulletMax} bullet points for the slide. ${extra}
`;
let powerpoint = "";
try {
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
temperature: temperature,
max_tokens: max_tokens,
});
let resp = completion.data.choices[0].text;
powerpoint = JSON.parse(resp.replace("\n", ""));
} catch (err) {
throw new Error(err);
}
return powerpoint;
}
module.exports = { callGpt };