forked from npgilman/ai_hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.js
52 lines (43 loc) · 1.47 KB
/
generator.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
// dependencies
const OPENAI = require('openai');
const fs = require('fs');
// init open ai
const openai = new OPENAI.OpenAI({
apiKey: "API-KEY-HERE",
dangerouslyAllowBrowser: true
});
// specify list of topics to generate pages for
var arr = [];
for (let i = 0; i < arr.length; i++) {
var queryBase = `function TEMPLATEPAGE() {
return (
<div className='d-flex flex-column flex-fill'>
<h1 className="align-self-center pt-4 mb-1"> title </h1>
<h5 className="align-self-center mt-0"> subtitle </h5>
<p className="align-self-center p-3"> content in page </p>
</div>
);
}
{
title: 'template',
path: '/template',
icon: <IoIcons.IoIosPaper />
}
export default TEMPLATEPAGE;
change the TEMPLATEPAGE to ${arr[i]} and create an educational summary of the topic in the p tag`;
request(queryBase, arr[i]);
}
// call gpt api and save result to file
async function request(query, name) {
const result = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{'role': 'user', 'content': query}],
max_tokens: 1000,
});
// console.log(result.choices[0].message.content);
fs.writeFile(`C:\\Users\\twinb\\OneDrive\\Desktop\\school\\ai_days\\ai_hackathon\\container\\${name}.js`, result.choices[0].message.content, err => {
if (err) {
console.error(err);
}
});
}