You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constpageSizeParam=100;// number of questions to retrieve per request
11
+
12
+
// Define GPT model parameters
13
+
constapiKey=process.env.OPENAI_API_KEY;
14
+
constgpt=newChatGPTAPI({
15
+
apiKey: apiKey,
16
+
})
17
+
18
+
// Make HTTP requests to the StackExchange API to retrieve recent questions from the Substrate site
19
+
constgetRecentQuestions=async(page=1)=>{
20
+
try{
21
+
constresponse=awaitaxios.get(apiUrl,{
22
+
params: {
23
+
page,
24
+
},
25
+
});
26
+
returnresponse.data.items;
27
+
}catch(error){
28
+
console.error(error);
29
+
}
30
+
};
31
+
32
+
// Extract question titles and bodies from the retrieved questions
33
+
constextractQuestionText=(questions)=>{
34
+
constquestionTexts=[];
35
+
questions.forEach((question)=>{
36
+
questionTexts.push(question.title);
37
+
questionTexts.push(question.body);
38
+
});
39
+
returnquestionTexts.join('\n');
40
+
};
41
+
42
+
// Use GPT to analyze the text and extract common topics
43
+
constanalyzeQuestionText=async(questionText)=>{
44
+
letquestion=`Imagine you are analyzing these questions, what themes do you see arise from them? Are there common questions that people ask? What are the common topics? Please provide a specific list of highly defined tutorial topics that could be written that would address these questions: ${questionText}`
45
+
constresponse=awaitgpt.sendMessage(question,{
46
+
max_tokens: 100,
47
+
n: 5,// number of topics to extract
48
+
stop: '\n',// use newline character to separate topics
49
+
presence_penalty: 0.5,
50
+
frequency_penalty: 0,
51
+
});
52
+
returnresponse;
53
+
// return response.choices[0].text;
54
+
};
55
+
56
+
// Use GPT to generate tutorial and blog post ideas based on the common topics
57
+
constgenerateIdeas=async(topics)=>{
58
+
constresponse=awaitgpt.sendMessage(`Tutorial and blog post ideas based on the topics: ${topics}`,{
59
+
max_tokens: 100,
60
+
n: 5,// number of ideas to generate
61
+
stop: '\n',// use newline character to separate ideas
62
+
presence_penalty: 0.5,
63
+
frequency_penalty: 0,
64
+
});
65
+
// return response.choices[0].text;
66
+
};
67
+
68
+
// Main function to retrieve recent questions from the Substrate site, analyze them using GPT, and generate tutorial and blog post ideas
0 commit comments