-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathllms.txt
More file actions
215 lines (137 loc) · 4.87 KB
/
Copy pathllms.txt
File metadata and controls
215 lines (137 loc) · 4.87 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Crate Documentation
**Version:** 0.3.0
**Format Version:** 43
# Module `rustdoc_llms`
# rustdoc-llms
Rust documentation helper that helps a Rust crate developer generate a file
`llms.txt` that helps provide context to large language models (LLMs).
Thanks to excellent work by the Rust team, rustdoc team, and rustdoc-md team.
## How to use this
Install:
```sh
cargo install rustdoc-llms
```
Use the tool when you're working on a crate and you want to document it:
```sh
rustdoc-llms
```
The tool creates two files:
* `target/doc/foo_bar.json` (this uses your own crate naming convention)
* `target/doc/llms.txt` (this is a markdown file created by rustdoc-md)
If you like, you can copy these files to the top level of your repository, which
can make the files easier to find for search engines and AI systems:
```sh
cp target/doc/foo_bar.json llms.json
cp target/doc/llms.txt llms.txt
```
## Scope
This Rust crate is deliberately small and simple. The purpose is to make it
slightly-easier to generate `llms` based on what's currently easy and available
for Rust crate developers.
Currently this tool calls existing command line interfaces, using `cargo` and
`rustdoc-md` with specialized compiler flags. If this tool is useful in
practice, then I intend to iterate to add command line arguments, options,
tests, and the like.
## Contributing
Pull requests are welcome. Issues are welcome.
If you want to help in other ways, or provide constructive criticism, or ask
questions directly, then please feel free to contact me. I'm Joel Parker
Henderson and my email is <joel@joelparkerhenderson.com>.
## What this does
This implements the help description [here](https://crates.io/crates/rustdoc-md).
Step 1: Generate JSON documentation:
```sh
RUSTC_BOOTSTRAP=1 RUSTDOCFLAGS="-Z unstable-options --output-format json" cargo doc --no-deps
```
Step 2: Convert from JSON into Markdown:
```sh
rustdoc-md --path target/doc/foo_bar.json --output target/doc/foo_bar.md
```
Step 3: Copy from Markdown file into LLMs file:
```sh
cp target/doc/foo_bar.json llms.json
cp target/doc/foo_bar.md llms.txt
```
## Modules
## Module `cargo_helpers`
```rust
pub(crate) mod cargo_helpers { /* ... */ }
```
### Functions
#### Function `lib_name`
Get a crate's lib name from its Cargo.toml file.
Steps:
1. Read the `Cargo.toml` file
2. Parse it as TOML
3. If there is a `[lib]` section with a `name` field, then return it.
4. If there is a `package.name`, then return it.
5. Otherwise return an error.
This llb name priority follows Cargo's explicit rules about library naming:
`[lib].name` takes precedence over `package.name`.
```rust
pub fn lib_name</* synthetic */ impl AsRef<Path>: AsRef<std::path::Path>>(path: impl AsRef<std::path::Path>) -> Result<String, Box<dyn std::error::Error>> { /* ... */ }
```
## Functions
### Function `main`
Run this command to generate the documentation LLMS file.
Example:
```sh
rustdoc-llms
```
You may wish to copy the output files to the root of your crate:
```sh
cp target/doc/foo_bar.json llms.json
cp target/doc/llms.txt llms.txt
```
```rust
pub(crate) fn main() { /* ... */ }
```
### Function `cargo_toml_path`
Get the path to the file `Cargo.toml`.
```rust
pub fn cargo_toml_path() -> std::path::PathBuf { /* ... */ }
```
### Function `documentation_json_path`
Get the target JSON file base name; this file is what cargo doc generates.
The name is the crate's lib target's name with all - chars turned into _.
Example:
```rust
use rustdoc_llms::*;
let path = rustdoc_md::documentation_json_path();
```
```rust
pub fn documentation_json_path() -> std::path::PathBuf { /* ... */ }
```
### Function `documentation_llms_path`
This is the name of the goal LLMS file that will be generated by rustdoc-md.
The industry standard file name is `llms.txt` though you can use anything.
Example:
```rust
use rustdoc_llms::*;
let path = rustdoc_md::documentation_llms_path();
```
```rust
pub fn documentation_llms_path() -> std::path::PathBuf { /* ... */ }
```
### Function `generate_documentation_json_file`
Run cargo doc with args to output one JSON file with all the combined documentation.
Example:
```rust
use rustdoc_llms::*;
let path = rustdoc_md::generate_documentation_json_file();
```
```rust
pub fn generate_documentation_json_file() { /* ... */ }
```
### Function `generate_documentation_llms_file`
Run rustdoc-md with an input file path and output file path.
Example:
```rust
use rustdoc_llms::*;
let input_json_path = rustdoc_md::documentation_json_path();
let output_llms_path = rustdoc_md::documentation_llms_path();
let path = rustdoc_md::generate_documentation_llms_file(input_json_path, output_llms_path);
```
```rust
pub fn generate_documentation_llms_file</* synthetic */ impl AsRef<Path>: AsRef<std::path::Path>, /* synthetic */ impl AsRef<Path>: AsRef<std::path::Path>>(input_json_path: impl AsRef<std::path::Path>, output_llms_path: impl AsRef<std::path::Path>) { /* ... */ }
```