Skip to content

Commit 338247c

Browse files
authored
Merge pull request #10 from andrewhong5297/prompt-config
Introduce Prompt customization into config
2 parents a28b708 + 1c90fa8 commit 338247c

16 files changed

+234
-51
lines changed

.eslintrc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ module.exports = {
1717
'react/react-in-jsx-scope': 'off',
1818
'react/prop-types': 'off',
1919
'@typescript-eslint/no-explicit-any': 'off',
20+
'prettier/prettier': [
21+
'error',
22+
{
23+
endOfLine: 'auto',
24+
},
25+
],
2026
},
2127
// "overrides": [
2228
// {

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ You will be prompted to enter the name of your project, GitHub url, and select w
131131

132132
**Note:** Do not skip entering these values or indexing may not work.
133133

134+
**Prompt Configuration:** You'll find prompt directions specified in `prompts.ts`, with some snippets customizable in the `autodoc.config.json`. The current prompts are developer focused and assume your repo is code focused. We will have more reference templates in the future.
135+
134136
Run the `index` command:
135137
```bash
136138
doc index

autodoc.config.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
"*.mdx",
2121
"*.toml",
2222
"*autodoc*"
23-
]
23+
],
24+
"filePrompt": "Write a detailed technical explanation of what this code does. \n Focus on the high-level purpose of the code and how it may be used in the larger project.\n Include code examples where appropriate. Keep you response between 100 and 300 words. \n DO NOT RETURN MORE THAN 300 WORDS.\n Output should be in markdown format.\n Do not just list the methods and classes in this file.",
25+
"folderPrompt": "Write a technical explanation of what the code in this file does\n and how it might fit into the larger project or work with other parts of the project.\n Give examples of how this code might be used. Include code examples where appropriate.\n Be concise. Include any information that may be relevant to a developer who is curious about this code.\n Keep you response under 400 words. Output should be in markdown format.\n Do not just list the files and folders in this folder.",
26+
"chatPrompt": "",
27+
"contentType": "code",
28+
"targetAudience": "smart developer",
29+
"linkHosted": false
2430
}

package-lock.json

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"license": "MIT",
2929
"dependencies": {
3030
"@dqbd/tiktoken": "^1.0.2",
31+
"@types/istextorbinary": "^2.3.1",
3132
"chalk": "^5.2.0",
3233
"cli-progress": "^3.12.0",
3334
"commander": "^10.0.0",

src/cli/commands/estimate/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export const estimate = async ({
1515
output,
1616
llms,
1717
ignore,
18+
filePrompt,
19+
folderPrompt,
20+
chatPrompt,
21+
contentType,
22+
targetAudience,
23+
linkHosted,
1824
}: AutodocRepoConfig) => {
1925
const json = path.join(output, 'docs', 'json/');
2026

@@ -32,6 +38,12 @@ export const estimate = async ({
3238
output: json,
3339
llms,
3440
ignore,
41+
filePrompt,
42+
folderPrompt,
43+
chatPrompt,
44+
contentType,
45+
targetAudience,
46+
linkHosted,
3547
},
3648
true,
3749
);

src/cli/commands/index/convertJsonToMarkdown.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export const convertJsonToMarkdown = async ({
1414
name: projectName,
1515
root: inputRoot,
1616
output: outputRoot,
17+
filePrompt: filePrompt,
18+
folderPrompt: folderPrompt,
19+
contentType: contentType,
20+
targetAudience: targetAudience,
21+
linkHosted: linkHosted,
1722
}: AutodocRepoConfig) => {
1823
/**
1924
* Count the number of files in the project
@@ -27,6 +32,11 @@ export const convertJsonToMarkdown = async ({
2732
return Promise.resolve();
2833
},
2934
ignore: [],
35+
filePrompt,
36+
folderPrompt,
37+
contentType,
38+
targetAudience,
39+
linkHosted,
3040
});
3141

3242
/**
@@ -83,6 +93,11 @@ export const convertJsonToMarkdown = async ({
8393
projectName,
8494
processFile,
8595
ignore: [],
96+
filePrompt,
97+
folderPrompt,
98+
contentType,
99+
targetAudience,
100+
linkHosted,
86101
});
87102
spinnerSuccess(`Created ${files} mardown files...`);
88103
};

src/cli/commands/index/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export const index = async ({
1212
output,
1313
llms,
1414
ignore,
15+
filePrompt,
16+
folderPrompt,
17+
chatPrompt,
18+
contentType,
19+
targetAudience,
20+
linkHosted,
1521
}: AutodocRepoConfig) => {
1622
const json = path.join(output, 'docs', 'json/');
1723
const markdown = path.join(output, 'docs', 'markdown/');
@@ -30,6 +36,12 @@ export const index = async ({
3036
output: json,
3137
llms,
3238
ignore,
39+
filePrompt,
40+
folderPrompt,
41+
chatPrompt,
42+
contentType,
43+
targetAudience,
44+
linkHosted,
3345
});
3446
updateSpinnerText('Processing repository...');
3547
spinnerSuccess();
@@ -45,6 +57,12 @@ export const index = async ({
4557
output: markdown,
4658
llms,
4759
ignore,
60+
filePrompt,
61+
folderPrompt,
62+
chatPrompt,
63+
contentType,
64+
targetAudience,
65+
linkHosted,
4866
});
4967
spinnerSuccess();
5068

@@ -56,6 +74,12 @@ export const index = async ({
5674
output: data,
5775
llms,
5876
ignore,
77+
filePrompt,
78+
folderPrompt,
79+
chatPrompt,
80+
contentType,
81+
targetAudience,
82+
linkHosted,
5983
});
6084
spinnerSuccess();
6185
};

src/cli/commands/index/processRepository.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export const processRepository = async (
3838
output: outputRoot,
3939
llms,
4040
ignore,
41+
filePrompt,
42+
folderPrompt,
43+
contentType,
44+
targetAudience,
45+
linkHosted,
4146
}: AutodocRepoConfig,
4247
dryRun?: boolean,
4348
) => {
@@ -58,19 +63,27 @@ export const processRepository = async (
5863
fileName,
5964
filePath,
6065
projectName,
66+
contentType,
67+
filePrompt,
68+
targetAudience,
69+
linkHosted,
6170
}): Promise<void> => {
6271
const content = await fs.readFile(filePath, 'utf-8');
6372
const markdownFilePath = path.join(outputRoot, filePath);
64-
const url = githubFileUrl(repositoryUrl, inputRoot, filePath);
73+
const url = githubFileUrl(repositoryUrl, inputRoot, filePath, linkHosted);
6574
const summaryPrompt = createCodeFileSummary(
6675
projectName,
6776
projectName,
6877
content,
78+
contentType,
79+
filePrompt,
6980
);
7081
const questionsPrompt = createCodeQuestions(
7182
projectName,
7283
projectName,
7384
content,
85+
contentType,
86+
targetAudience,
7487
);
7588
const summaryLength = encoding.encode(summaryPrompt).length;
7689
const questionLength = encoding.encode(questionsPrompt).length;
@@ -167,7 +180,10 @@ export const processRepository = async (
167180
folderName,
168181
folderPath,
169182
projectName,
183+
contentType,
184+
folderPrompt,
170185
shouldIgnore,
186+
linkHosted,
171187
}): Promise<void> => {
172188
/**
173189
* For now we don't care about folders
@@ -179,7 +195,8 @@ export const processRepository = async (
179195
const contents = (await fs.readdir(folderPath)).filter(
180196
(fileName) => !shouldIgnore(fileName),
181197
);
182-
const url = githubFolderUrl(repositoryUrl, inputRoot, folderPath);
198+
// eslint-disable-next-line prettier/prettier
199+
const url = githubFolderUrl(repositoryUrl, inputRoot, folderPath, linkHosted);
183200
const allFiles: (FileSummary | null)[] = await Promise.all(
184201
contents.map(async (fileName) => {
185202
const entryPath = path.join(folderPath, fileName);
@@ -223,7 +240,14 @@ export const processRepository = async (
223240
);
224241

225242
const summary = await callLLM(
226-
folderSummaryPrompt(folderPath, projectName, files, folders),
243+
folderSummaryPrompt(
244+
folderPath,
245+
projectName,
246+
files,
247+
folders,
248+
contentType,
249+
folderPrompt,
250+
),
227251
models[LLMModels.GPT4].llm,
228252
);
229253

@@ -252,7 +276,7 @@ export const processRepository = async (
252276
};
253277

254278
/**
255-
* Get the numver of files and folderfs in the project
279+
* Get the number of files and folders in the project
256280
*/
257281

258282
const filesAndFolders = async (): Promise<{
@@ -271,6 +295,11 @@ export const processRepository = async (
271295
return Promise.resolve();
272296
},
273297
ignore,
298+
filePrompt,
299+
folderPrompt,
300+
contentType,
301+
targetAudience,
302+
linkHosted,
274303
}),
275304
traverseFileSystem({
276305
inputPath: inputRoot,
@@ -280,6 +309,11 @@ export const processRepository = async (
280309
return Promise.resolve();
281310
},
282311
ignore,
312+
filePrompt,
313+
folderPrompt,
314+
contentType,
315+
targetAudience,
316+
linkHosted,
283317
}),
284318
]);
285319

@@ -301,6 +335,11 @@ export const processRepository = async (
301335
projectName,
302336
processFile,
303337
ignore,
338+
filePrompt,
339+
folderPrompt,
340+
contentType,
341+
targetAudience,
342+
linkHosted,
304343
});
305344
spinnerSuccess(`Processing ${files} files...`);
306345

@@ -313,6 +352,11 @@ export const processRepository = async (
313352
projectName,
314353
processFolder,
315354
ignore,
355+
filePrompt,
356+
folderPrompt,
357+
contentType,
358+
targetAudience,
359+
linkHosted,
316360
});
317361
spinnerSuccess(`Processing ${folders} folders... `);
318362
stopSpinner();

0 commit comments

Comments
 (0)