Improve the content writing performance

pull/3832/head
Kamran Ahmed 2 years ago
parent e66bff74bf
commit 8b2f12fcdd
  1. 51
      bin/roadmap-content.cjs

@ -66,7 +66,7 @@ function writeTopicContent(currTopicUrl) {
prompt = `I am reading a guide about "${roadmapTitle}". I am on the topic "${parentTopic}". I want to know more about "${parentTopic}". Write me a brief summary for that topic. Content should be in markdown. Behave as if you are the author of the guide.`;
}
console.log(`Genearting '${childTopic || parentTopic}'...`);
console.log(`Generating '${childTopic || parentTopic}'...`);
return new Promise((resolve, reject) => {
openai
@ -90,30 +90,14 @@ function writeTopicContent(currTopicUrl) {
});
}
async function run() {
const topicUrlToPathMapping = getFilesInFolder(ROADMAP_CONTENT_DIR);
const roadmapJson = require(path.join(ROADMAP_JSON_DIR, `${roadmapId}.json`));
const groups = roadmapJson?.mockup?.controls?.control?.filter(
(control) =>
control.typeID === '__group__' &&
!control.properties?.controlName?.startsWith('ext_link')
);
if (!OPEN_AI_API_KEY) {
console.log('----------------------------------------');
console.log('OPEN_AI_API_KEY not found. Skipping openai api calls...');
console.log('----------------------------------------');
}
for (let group of groups) {
async function writeFileForGroup(group, topicUrlToPathMapping) {
const topicId = group?.properties?.controlName;
const topicTitle = group?.children?.controls?.control?.find(
(control) => control?.typeID === 'Label'
)?.properties?.text;
const currTopicUrl = topicId?.replace(/^\d+-/g, '/')?.replace(/:/g, '/');
if (!currTopicUrl) {
continue;
return;
}
const contentFilePath = topicUrlToPathMapping[currTopicUrl];
@ -128,15 +112,16 @@ async function run() {
if (!isFileEmpty) {
console.log(`Ignoring ${topicId}. Not empty.`);
continue;
return;
}
let newFileContent = `# ${topicTitle}`;
if (!OPEN_AI_API_KEY) {
console.log(`Writing ${topicId}..`);
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');
continue;
return;
}
const topicContent = await writeTopicContent(currTopicUrl);
@ -150,6 +135,30 @@ async function run() {
// console.log(topicTitle);
// console.log(topicUrlToPathMapping[currTopicUrl]);
}
async function run() {
const topicUrlToPathMapping = getFilesInFolder(ROADMAP_CONTENT_DIR);
const roadmapJson = require(path.join(ROADMAP_JSON_DIR, `${roadmapId}.json`));
const groups = roadmapJson?.mockup?.controls?.control?.filter(
(control) =>
control.typeID === '__group__' &&
!control.properties?.controlName?.startsWith('ext_link')
);
if (!OPEN_AI_API_KEY) {
console.log('----------------------------------------');
console.log('OPEN_AI_API_KEY not found. Skipping openai api calls...');
console.log('----------------------------------------');
}
const writePromises = [];
for (let group of groups) {
writePromises.push(writeFileForGroup(group, topicUrlToPathMapping));
}
console.log('Waiting for all files to be written...');
await Promise.all(writePromises);
}
run()

Loading…
Cancel
Save