Skip to content

Commit 1c90fa8

Browse files
make linkHosted boolean work
1 parent fe4590c commit 1c90fa8

File tree

10 files changed

+49
-12
lines changed

10 files changed

+49
-12
lines changed

autodoc.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
"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.",
2626
"chatPrompt": "",
2727
"contentType": "code",
28-
"targetAudience": "smart developer"
28+
"targetAudience": "smart developer",
29+
"linkHosted": false
2930
}

src/cli/commands/estimate/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const estimate = async ({
1919
folderPrompt,
2020
chatPrompt,
2121
contentType,
22-
targetAudience
22+
targetAudience,
23+
linkHosted,
2324
}: AutodocRepoConfig) => {
2425
const json = path.join(output, 'docs', 'json/');
2526

@@ -41,7 +42,8 @@ export const estimate = async ({
4142
folderPrompt,
4243
chatPrompt,
4344
contentType,
44-
targetAudience
45+
targetAudience,
46+
linkHosted,
4547
},
4648
true,
4749
);

src/cli/commands/index/convertJsonToMarkdown.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const convertJsonToMarkdown = async ({
1818
folderPrompt: folderPrompt,
1919
contentType: contentType,
2020
targetAudience: targetAudience,
21+
linkHosted: linkHosted,
2122
}: AutodocRepoConfig) => {
2223
/**
2324
* Count the number of files in the project
@@ -35,6 +36,7 @@ export const convertJsonToMarkdown = async ({
3536
folderPrompt,
3637
contentType,
3738
targetAudience,
39+
linkHosted,
3840
});
3941

4042
/**
@@ -95,6 +97,7 @@ export const convertJsonToMarkdown = async ({
9597
folderPrompt,
9698
contentType,
9799
targetAudience,
100+
linkHosted,
98101
});
99102
spinnerSuccess(`Created ${files} mardown files...`);
100103
};

src/cli/commands/index/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const index = async ({
1717
chatPrompt,
1818
contentType,
1919
targetAudience,
20+
linkHosted,
2021
}: AutodocRepoConfig) => {
2122
const json = path.join(output, 'docs', 'json/');
2223
const markdown = path.join(output, 'docs', 'markdown/');
@@ -40,6 +41,7 @@ export const index = async ({
4041
chatPrompt,
4142
contentType,
4243
targetAudience,
44+
linkHosted,
4345
});
4446
updateSpinnerText('Processing repository...');
4547
spinnerSuccess();
@@ -60,6 +62,7 @@ export const index = async ({
6062
chatPrompt,
6163
contentType,
6264
targetAudience,
65+
linkHosted,
6366
});
6467
spinnerSuccess();
6568

@@ -76,6 +79,7 @@ export const index = async ({
7679
chatPrompt,
7780
contentType,
7881
targetAudience,
82+
linkHosted,
7983
});
8084
spinnerSuccess();
8185
};

src/cli/commands/index/processRepository.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const processRepository = async (
4242
folderPrompt,
4343
contentType,
4444
targetAudience,
45+
linkHosted,
4546
}: AutodocRepoConfig,
4647
dryRun?: boolean,
4748
) => {
@@ -65,10 +66,11 @@ export const processRepository = async (
6566
contentType,
6667
filePrompt,
6768
targetAudience,
69+
linkHosted,
6870
}): Promise<void> => {
6971
const content = await fs.readFile(filePath, 'utf-8');
7072
const markdownFilePath = path.join(outputRoot, filePath);
71-
const url = githubFileUrl(repositoryUrl, inputRoot, filePath);
73+
const url = githubFileUrl(repositoryUrl, inputRoot, filePath, linkHosted);
7274
const summaryPrompt = createCodeFileSummary(
7375
projectName,
7476
projectName,
@@ -181,6 +183,7 @@ export const processRepository = async (
181183
contentType,
182184
folderPrompt,
183185
shouldIgnore,
186+
linkHosted,
184187
}): Promise<void> => {
185188
/**
186189
* For now we don't care about folders
@@ -192,7 +195,8 @@ export const processRepository = async (
192195
const contents = (await fs.readdir(folderPath)).filter(
193196
(fileName) => !shouldIgnore(fileName),
194197
);
195-
const url = githubFolderUrl(repositoryUrl, inputRoot, folderPath);
198+
// eslint-disable-next-line prettier/prettier
199+
const url = githubFolderUrl(repositoryUrl, inputRoot, folderPath, linkHosted);
196200
const allFiles: (FileSummary | null)[] = await Promise.all(
197201
contents.map(async (fileName) => {
198202
const entryPath = path.join(folderPath, fileName);
@@ -295,6 +299,7 @@ export const processRepository = async (
295299
folderPrompt,
296300
contentType,
297301
targetAudience,
302+
linkHosted,
298303
}),
299304
traverseFileSystem({
300305
inputPath: inputRoot,
@@ -308,6 +313,7 @@ export const processRepository = async (
308313
folderPrompt,
309314
contentType,
310315
targetAudience,
316+
linkHosted,
311317
}),
312318
]);
313319

@@ -333,6 +339,7 @@ export const processRepository = async (
333339
folderPrompt,
334340
contentType,
335341
targetAudience,
342+
linkHosted,
336343
});
337344
spinnerSuccess(`Processing ${files} files...`);
338345

@@ -349,6 +356,7 @@ export const processRepository = async (
349356
folderPrompt,
350357
contentType,
351358
targetAudience,
359+
linkHosted,
352360
});
353361
spinnerSuccess(`Processing ${folders} folders... `);
354362
stopSpinner();

src/cli/commands/init/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const makeConfigTemplate = (
4747
chatPrompt: '',
4848
contentType: 'code',
4949
targetAudience: 'smart developer',
50+
linkHosted: false,
5051
};
5152
};
5253

src/cli/commands/query/createChatChain.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Chat History:
1212
Follow Up Input: {question}
1313
Standalone question:`);
1414

15+
// eslint-disable-next-line prettier/prettier
1516
const makeQAPrompt = (projectName: string, repositoryUrl: string, contentType: string, chatPrompt: string, targetAudience: string) =>
1617
PromptTemplate.fromTemplate(
1718
`You are an AI assistant for a software project called ${projectName}. You are trained on all the ${contentType} that makes up this project.
@@ -58,6 +59,7 @@ export const makeChain = (
5859
prompt: CONDENSE_PROMPT,
5960
});
6061

62+
// eslint-disable-next-line prettier/prettier
6163
const QA_PROMPT = makeQAPrompt(projectName, repositoryUrl, contentType, chatPrompt, targetAudience);
6264
const docChain = loadQAChain(
6365
new OpenAIChat({

src/cli/utils/FileUtil.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,28 @@ export const githubFileUrl = (
1616
githubRoot: string,
1717
inputRoot: string,
1818
filePath: string,
19+
linkHosted: boolean,
1920
): string => {
20-
return `${githubRoot}/blob/master/${filePath.substring(
21-
inputRoot.length - 1,
22-
)}`;
21+
if (linkHosted) {
22+
return `${githubRoot}/${filePath.substring(inputRoot.length - 1)}`;
23+
} else {
24+
return `${githubRoot}/blob/master/${filePath.substring(
25+
inputRoot.length - 1,
26+
)}`;
27+
}
2328
};
2429

2530
export const githubFolderUrl = (
2631
githubRoot: string,
2732
inputRoot: string,
2833
folderPath: string,
34+
linkHosted: boolean,
2935
): string => {
30-
return `${githubRoot}/tree/master/${folderPath.substring(
31-
inputRoot.length - 1,
32-
)}`;
36+
if (linkHosted) {
37+
return `${githubRoot}/${folderPath.substring(inputRoot.length - 1)}`;
38+
} else {
39+
return `${githubRoot}/tree/master/${folderPath.substring(
40+
inputRoot.length - 1,
41+
)}`;
42+
}
3343
};

src/cli/utils/traverseFileSystem.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const traverseFileSystem = async (
99
): Promise<void> => {
1010
try {
1111
// eslint-disable-next-line prettier/prettier
12-
const { inputPath, projectName, processFile, processFolder, ignore, filePrompt, folderPrompt, contentType, targetAudience } = params;
12+
const { inputPath, projectName, processFile, processFolder, ignore, filePrompt, folderPrompt, contentType, targetAudience, linkHosted } = params;
1313

1414
try {
1515
await fs.access(inputPath);
@@ -43,6 +43,7 @@ export const traverseFileSystem = async (
4343
folderPrompt,
4444
contentType,
4545
targetAudience,
46+
linkHosted,
4647
});
4748
}
4849
}),
@@ -61,6 +62,7 @@ export const traverseFileSystem = async (
6162
filePrompt,
6263
contentType,
6364
targetAudience,
65+
linkHosted,
6466
});
6567
}
6668
}),

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type AutodocRepoConfig = {
1616
chatPrompt: string;
1717
contentType: string;
1818
targetAudience: string;
19+
linkHosted: boolean;
1920
};
2021

2122
export type FileSummary = {
@@ -33,6 +34,7 @@ export type ProcessFileParams = {
3334
contentType: string;
3435
filePrompt: string;
3536
targetAudience: string;
37+
linkHosted: boolean;
3638
};
3739

3840
export type ProcessFile = (params: ProcessFileParams) => Promise<void>;
@@ -54,6 +56,7 @@ export type ProcessFolderParams = {
5456
contentType: string;
5557
folderPrompt: string;
5658
targetAudience: string;
59+
linkHosted: boolean;
5760
shouldIgnore: (fileName: string) => boolean;
5861
};
5962

@@ -69,6 +72,7 @@ export type TraverseFileSystemParams = {
6972
folderPrompt: string;
7073
contentType: string;
7174
targetAudience: string;
75+
linkHosted: boolean;
7276
};
7377

7478
export enum LLMModels {

0 commit comments

Comments
 (0)