-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgpt-docs.mjs
More file actions
76 lines (68 loc) · 2.65 KB
/
Copy pathgpt-docs.mjs
File metadata and controls
76 lines (68 loc) · 2.65 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { globSync } from "glob";
import { basename, join, extname, resolve } from "path";
import { createCompletion, loadModel } from "gpt4all";
import fs from "fs";
const GPT_PROMPT =
"Please write a summary for that Typescript API Reference with several sentences in more human way";
console.log("Loading model");
const model = await loadModel("Nous-Hermes-2-Mistral-7B-DPO.Q4_0.gguf", {
verbose: true,
});
const generateDescription = async (filePath) => {
console.log(`Generating content for ${resolve(filePath)}`);
console.time("EXECUTE");
const data = fs.readFileSync(filePath).toString();
const chat = await model.createChatSession({
temperature: 0.8,
systemPrompt: `### System:\n${GPT_PROMPT}.\n\n`,
});
const result = await createCompletion(chat, data);
console.timeEnd("EXECUTE");
return result.choices[0].message.content;
}
// Modules
{
for (const modulePath of globSync("./modules/*", { onlyDirectories: true })) {
const moduleName = basename(modulePath);
console.log(`Generating documentation for module ${moduleName}`);
const classList = globSync(`./modules/${moduleName}/docs/classes/*`);
const outputPath = join(process.cwd(), 'docs', `${moduleName}.md`);
const output = [];
output.push(`# ${moduleName}`);
output.push("");
if (!classList.length) {
output.push("No data available");
}
for (const classPath of classList) {
const className = basename(classPath, extname(classPath));
output.push(`## ${className}`);
output.push("");
output.push(await generateDescription(classPath))
output.push("");
}
fs.writeFileSync(outputPath, output.join("\n"));
}
}
// Services
{
for (const modulePath of globSync("./services/*", { onlyDirectories: true })) {
const moduleName = basename(modulePath);
console.log(`Generating documentation for service ${moduleName}`);
const classList = globSync(`./services/${moduleName}/docs/classes/*`);
const outputPath = join(process.cwd(), 'docs', `${moduleName}.md`);
const output = [];
output.push(`# ${moduleName}`);
output.push("");
if (!classList.length) {
output.push("No data available");
}
for (const classPath of classList) {
const className = basename(classPath, extname(classPath));
output.push(`## ${className}`);
output.push("");
output.push(await generateDescription(classPath))
output.push("");
}
fs.writeFileSync(outputPath, output.join("\n"));
}
}