Skip to content

Commit 8541107

Browse files
committed
feat(documentation)📝: Add guided tutorial for llamabot docs write command
- Create a new documentation file for the LlamaBot CLI. - Include usage instructions and options for `llamabot docs write`. - Provide information on the `--force` flag usage. - Explain requirements for target documentation file formatting and placement. - Detail necessary frontmatter key-value pairs for the command.
1 parent 84ebf42 commit 8541107

File tree

2 files changed

+131
-17
lines changed

2 files changed

+131
-17
lines changed

‎docs/cli/docs.md‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
intents:
3+
- Provide reader with a guided tutorial that shows how to use the `llamabot docs write`
4+
command at the terminal to generate documentation.
5+
- Specifically add in information about the `--force` flag.
6+
- Describe the frontmatter key-value pairs needed to make it work.
7+
linked_files:
8+
- llamabot/cli/docs.py
9+
- pyproject.toml
10+
---
11+
12+
# LlamaBot Documentation
13+
14+
## Installation
15+
16+
To install LlamaBot, follow these steps:
17+
18+
1. Ensure you have Python 3.10 or higher installed on your system.
19+
2. Install LlamaBot using pip:
20+
21+
```bash
22+
pip install llamabot
23+
```
24+
25+
3. Verify the installation by running:
26+
27+
```bash
28+
llamabot --help
29+
```
30+
31+
## Usage
32+
33+
To use LlamaBot to generate documentation, run the following command in the terminal:
34+
35+
```bash
36+
llamabot docs write <path_to_markdown_file>
37+
```
38+
39+
### Options
40+
41+
- `--force`: Use this flag to force the documentation update even if it is not detected as out of date.
42+
43+
## Additional Information
44+
45+
For more information, refer to the [official documentation](https://llamabotdocs.com).
46+
47+
## Explanation
48+
49+
To make the `llamabot docs write` command work, ensure that your Markdown source files are properly formatted and located in the correct directory. The command will read the source files, check if the documentation is up-to-date, and update it if necessary. If you use the `--force` flag, the documentation will be updated regardless of its current status.
50+
51+
### Requirements for Target Documentation File
52+
53+
1. **Proper Formatting**: Ensure your Markdown files are correctly formatted.
54+
2. **Correct Directory**: Place your Markdown files in the appropriate directory as expected by the `llamabot docs write` command.
55+
3. **Linked Files**: If your documentation references other files, ensure these are correctly linked and accessible.
56+
57+
### Frontmatter Key-Value Pairs
58+
59+
To use the `llamabot docs write` command effectively, your Markdown files should include the following frontmatter:
60+
61+
```markdown
62+
---
63+
intents:
64+
- Point 1 that the documentation should cover.
65+
- Point 2 that the documentation should cover.
66+
- ...
67+
linked_files:
68+
- path/to/relevant_file1.py
69+
- path/to/relevant_file2.toml
70+
- ...
71+
---
72+
```
73+
74+
By following these guidelines, you can effectively use LlamaBot to manage and update your documentation.

‎llamabot/cli/docs.py‎

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from typer import Typer
44
from pathlib import Path
55
import frontmatter
6-
from pydantic import BaseModel, Field
7-
from llamabot import prompt, StructuredBot, SimpleBot
6+
from pydantic import BaseModel, Field, model_validator
7+
from llamabot import prompt, StructuredBot
88
from pyprojroot import here
99

1010
from pydantic import ConfigDict
1111

12+
1213
app = Typer()
1314

1415

@@ -47,6 +48,21 @@ def save(self):
4748
f.write(frontmatter.dumps(self.post))
4849

4950

51+
class DocumentationContent(BaseModel):
52+
"""Content related to documentation."""
53+
54+
content: str = Field(..., description="The documentation content.")
55+
56+
@model_validator(mode="after")
57+
def check_content(self):
58+
"""Validate the content field."""
59+
if self.content.startswith("```") or self.content.endswith("```"):
60+
raise ValueError(
61+
"Documentation content should not start or end with triple backticks."
62+
)
63+
return self
64+
65+
5066
class DocumentationOutOfDate(BaseModel):
5167
"""Status indicating whether a documentation is out of date."""
5268

@@ -56,7 +72,7 @@ class DocumentationOutOfDate(BaseModel):
5672

5773

5874
@prompt
59-
def ood_checker_sysprompt():
75+
def ood_checker_sysprompt() -> str:
6076
"""You are an expert in documentation management.
6177
You will be provided information about a written documentation file,
6278
what the documentation is intended to convey,
@@ -67,7 +83,9 @@ def ood_checker_sysprompt():
6783

6884
@prompt
6985
def documentation_information(source_file: MarkdownSourceFile) -> str:
70-
"""## Referenced source files
86+
"""Here, I will provide you with contextual information to do your work.
87+
88+
## Referenced source files
7189
7290
These are the source files to reference:
7391
@@ -96,46 +114,68 @@ def documentation_information(source_file: MarkdownSourceFile) -> str:
96114
Here is the intent about the documentation:
97115
98116
{% for intent in source_file.post.get("intents", []) %}- {{ intent }}{% endfor %}
117+
-----
99118
"""
100119

101120

102121
@prompt
103122
def docwriter_sysprompt():
104-
"""You are an expert in documentation writing.
123+
"""
124+
[[ Persona ]]
125+
You are an expert in documentation writing.
105126
127+
[[ Context ]]
106128
You will be provided a documentation source,
107129
a list of what the documentation is intended to cover,
108130
and a list of linked source files.
109131
132+
[[ Instructions ]]
110133
Based on the intended messages information that the documentation is supposed to cover
111134
and the content of linked source files,
112135
please edit or create the documentation,
113136
ensuring that the documentation matches the intents
114137
and has the correct content from the linked source files.
138+
Return only the Markdown content of the documentation without the surrounding fence.
115139
"""
116140

117141

118142
@app.command()
119143
def write(file_path: Path, force: bool = False):
120144
"""Write the documentation based on the given source file.
121145
146+
The Markdown file should have frontmatter that looks like this:
147+
148+
```markdown
149+
---
150+
intents:
151+
- Point 1 that the documentation should cover.
152+
- Point 2 that the documentation should cover.
153+
- ...
154+
linked_files:
155+
- path/to/relevant_file1.py
156+
- path/to/relevant_file2.toml
157+
- ...
158+
---
159+
```
160+
122161
:param file_path: Path to the Markdown source file.
123162
:param force: Force writing the documentation even if it is not out of date.
124163
"""
125164
src_file = MarkdownSourceFile(file_path)
126165

127-
if not src_file.post.content: # i.e. the documentation is empty
128-
docwriter = SimpleBot(system_prompt=docwriter_sysprompt())
129-
response = docwriter(documentation_information(src_file))
130-
src_file.post.content = response.content
166+
docwriter = StructuredBot(
167+
system_prompt=docwriter_sysprompt(),
168+
pydantic_model=DocumentationContent,
169+
model_name="gpt-4o",
170+
)
171+
ood_checker = StructuredBot(
172+
system_prompt=ood_checker_sysprompt(), pydantic_model=DocumentationOutOfDate
173+
)
174+
result: DocumentationOutOfDate = ood_checker(documentation_information(src_file))
131175

132-
else:
133-
ood_checker = StructuredBot(
134-
system_prompt=ood_checker_sysprompt(), pydantic_model=DocumentationOutOfDate
176+
if not src_file.post.content or result.is_out_of_date or force:
177+
response: DocumentationContent = docwriter(
178+
documentation_information(src_file) + "\nNow please write the docs."
135179
)
136-
result = ood_checker(documentation_information(src_file))
137-
if result.is_out_of_date or force:
138-
docwriter = SimpleBot(system_prompt=docwriter_sysprompt())
139-
response = docwriter(documentation_information(src_file))
140-
src_file.post.content = response.content
180+
src_file.post.content = response.content
141181
src_file.save()

0 commit comments

Comments
 (0)