-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-outline.js
46 lines (38 loc) · 1.56 KB
/
create-outline.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
import dotenv from 'dotenv';
dotenv.config();
import axios from 'axios';
import { ChatGPTAPI } from 'chatgpt';
// Define GPT model parameters
const apiKey = process.env.OPENAI_API_KEY;
const gpt = new ChatGPTAPI({
apiKey: apiKey,
})
// Use GPT to analyze the text and extract common topics
const getOutline = async (topic) => {
let question = `
You are a technical writer and you have been tasked to write a tutorial with the title of "${topic}".
Your first job is to create an outline for the tutorial. In your response to this prompt, please provide a
step-by-step outline for the tutorial in HTML format. In each step of the outline, please provide a
brief description of what the reader will learn in that step. You can use the following format for each step:
<li>Step 1: [Name of Step]: <i><description of what the reader will learn in this step></i></li>
<li>Step 2: [Name of Step]: <i><description of what the reader will learn in this step></i></li>
etc.
`
const response = await gpt.sendMessage(question, {
max_tokens: 100,
n: 5, // number of topics to extract
stop: '\n', // use newline character to separate topics
presence_penalty: 0.5,
frequency_penalty: 0,
});
return response.text;
};
// Main function to retrieve recent questions from the Substrate site, analyze them using GPT, and generate tutorial and blog post ideas
const createOutline = async (topic) => {
let outline = await getOutline(topic);
console.log(outline);
return outline;
}
// Call the main function
createOutline();
export { createOutline };