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 7df7243

Browse files
add a web server and view
1 parent b9ab647 commit 7df7243

File tree

11 files changed

+2204
-23
lines changed

11 files changed

+2204
-23
lines changed

‎index.js‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
12
import dotenv from 'dotenv';
23
dotenv.config();
34

45
import axios from 'axios';
56
import cheerio from 'cheerio';
67
import { ChatGPTAPI } from 'chatgpt';
8+
import fs from 'fs/promises';
79

810
// Define StackExchange API endpoint and parameters for the Substrate site
911
const apiUrl = 'https://api.stackexchange.com/2.3/questions?site=substrate&pagesize=50';
@@ -41,27 +43,15 @@ const extractQuestionText = (questions) => {
4143

4244
// Use GPT to analyze the text and extract common topics
4345
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}`
46+
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, only provide the list in your response and nothing else: ${questionText}`
4547
const response = await gpt.sendMessage(question, {
4648
max_tokens: 100,
4749
n: 5, // number of topics to extract
4850
stop: '\n', // use newline character to separate topics
4951
presence_penalty: 0.5,
5052
frequency_penalty: 0,
5153
});
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-
});
54+
return response.text;
6555
// return response.choices[0].text;
6656
};
6757

@@ -70,12 +60,11 @@ const main = async () => {
7060
const questions = await getRecentQuestions();
7161
const questionText = extractQuestionText(questions);
7262
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);
63+
await fs.writeFile('topics.txt', topics);
64+
return topics;
7865
};
7966

8067
// Call the main function
81-
main();
68+
main();
69+
70+
export { main };

0 commit comments

Comments
(0)

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