forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
51 lines (41 loc) · 1.18 KB
/
index.mjs
File metadata and controls
51 lines (41 loc) · 1.18 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
import { readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { buildApiDocLink } from './utils/buildApiDocLink.mjs';
/**
* This generator generates a llms.txt file to provide information to LLMs at
* inference time
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {GeneratorMetadata<Input, string>}
*/
export default {
name: 'llms-txt',
version: '1.0.0',
description:
'Generates a llms.txt file to provide information to LLMs at inference time',
dependsOn: 'ast',
/**
* Generates a llms.txt file
*
* @param {Input} entries
* @param {Partial<GeneratorOptions>} options
* @returns {Promise<void>}
*/
async generate(entries, { output }) {
const template = await readFile(
join(import.meta.dirname, 'template.txt'),
'utf-8'
);
const apiDocsLinks = entries
// Filter non top-level headings
.filter(entry => entry.heading.depth === 1)
.map(entry => `- ${buildApiDocLink(entry)}`)
.join('\n');
const filledTemplate = `${template}${apiDocsLinks}`;
if (output) {
await writeFile(join(output, 'llms.txt'), filledTemplate);
}
return filledTemplate;
},
};