Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 29cd038

Browse files
pushing up
0 parents commit 29cd038

File tree

5 files changed

+968
-0
lines changed

5 files changed

+968
-0
lines changed

‎.env.sample‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPENAI_API_KEY=

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
node_modules/

‎index.js‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import dotenv from 'dotenv';
2+
dotenv.config();
3+
4+
import axios from 'axios';
5+
import cheerio from 'cheerio';
6+
import { ChatGPTAPI } from 'chatgpt';
7+
8+
// Define StackExchange API endpoint and parameters for the Substrate site
9+
const apiUrl = 'https://api.stackexchange.com/2.3/questions?site=substrate&pagesize=50';
10+
const pageSizeParam = 100; // number of questions to retrieve per request
11+
12+
// Define GPT model parameters
13+
const apiKey = process.env.OPENAI_API_KEY;
14+
const gpt = new ChatGPTAPI({
15+
apiKey: apiKey,
16+
})
17+
18+
// Make HTTP requests to the StackExchange API to retrieve recent questions from the Substrate site
19+
const getRecentQuestions = async (page = 1) => {
20+
try {
21+
const response = await axios.get(apiUrl, {
22+
params: {
23+
page,
24+
},
25+
});
26+
return response.data.items;
27+
} catch (error) {
28+
console.error(error);
29+
}
30+
};
31+
32+
// Extract question titles and bodies from the retrieved questions
33+
const extractQuestionText = (questions) => {
34+
const questionTexts = [];
35+
questions.forEach((question) => {
36+
questionTexts.push(question.title);
37+
questionTexts.push(question.body);
38+
});
39+
return questionTexts.join('\n');
40+
};
41+
42+
// Use GPT to analyze the text and extract common topics
43+
const analyzeQuestionText = async (questionText) => {
44+
let question = `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+
const response = await gpt.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+
return response;
53+
// return response.choices[0].text;
54+
};
55+
56+
// Use GPT to generate tutorial and blog post ideas based on the common topics
57+
const generateIdeas = async (topics) => {
58+
const response = await gpt.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
69+
const main = async () => {
70+
const questions = await getRecentQuestions();
71+
const questionText = extractQuestionText(questions);
72+
const topics = await analyzeQuestionText(questionText);
73+
console.log('Common topics:');
74+
console.log(topics);
75+
const ideas = await generateIdeas(topics);
76+
console.log('Tutorial and blog post ideas:');
77+
console.log(ideas);
78+
};
79+
80+
// Call the main function
81+
main();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /