Skip to content

Commit 80e4bf6

Browse files
ci(docs): add automatic doc generation to pre-commit (#35)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * Documentation * Updated branding to “Open Data Hub Llama Stack” and expanded build instructions with clear prerequisites and step-by-step guidance. * Added a distribution overview including a generated table mapping APIs to their providers. * Clarified how to edit the Containerfile template and reiterated not to modify the generated file directly. * Chores * Added a pre-commit check to automatically generate distribution documentation from the configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 6c924ac + 854b59d commit 80e4bf6

File tree

4 files changed

+140
-9
lines changed

4 files changed

+140
-9
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ repos:
5757
files: ^distribution/.*$
5858
additional_dependencies:
5959
- llama-stack==0.2.21
60+
61+
- id: doc-gen
62+
name: Distribution Documentation
63+
entry: ./scripts/gen_distro_docs.py
64+
language: python
65+
pass_filenames: false
66+
require_serial: true
67+
files: ^distribution/run\.yaml$
68+
additional_dependencies:
69+
- pyyaml==6.0.2

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# Red Hat Distribution Build Instructions
1+
# Open Data Hub Llama Stack Distribution
22

3-
This directory contains the necessary files to build a Red Hat compatible container image for the llama-stack.
3+
This directory contains the necessary files to build an Open Data Hub-compatible container image for [Llama Stack](https://github.com/llamastack/llama-stack).
44

5-
## Prerequisites
5+
To learn more about the distribution image content, see the [README](distribution/README.md) in the `distribution/` directory.
6+
7+
## Build Instructions
8+
9+
### Prerequisites
610

711
- Python >=3.11
812
- `llama` CLI tool installed: `pip install llama-stack`
913
- Podman or Docker installed
1014

11-
## Generating the Containerfile
15+
### Generating the Containerfile
1216

1317
The Containerfile is auto-generated from a template. To generate it:
1418

@@ -23,26 +27,26 @@ This will:
2327
- Generate dependencies using `llama stack build`
2428
- Create a new `Containerfile` with the required dependencies
2529

26-
## Editing the Containerfile
30+
### Editing the Containerfile
2731

2832
The Containerfile is auto-generated from a template. To edit it, you can modify the template in `distribution/Containerfile.in` and run the build script again.
2933
NEVER edit the generated `Containerfile` manually.
3034

31-
## Building the Container Image
35+
### Building the Container Image
3236

3337
Once the Containerfile is generated, you can build the image using either Podman or Docker:
3438

35-
### Using Podman build image for x86_64
39+
#### Using Podman build image for x86_64
3640

3741
```bash
3842
podman build --platform linux/amd64 -f distribution/Containerfile -t rh .
3943
```
4044

41-
## Notes
45+
### Notes
4246

4347
- The generated Containerfile should not be modified manually as it will be overwritten the next time you run the build script
4448

45-
## Push the image to a registry
49+
### Push the image to a registry
4650

4751
```bash
4852
podman push <build-ID> quay.io/opendatahub/llama-stack:rh-distribution

distribution/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!-- This file is automatically generated by scripts/gen_distro_doc.py - do not update manually -->
2+
3+
# Open Data Hub Llama Stack Distribution Image
4+
5+
This image contains the official Open Data Hub Llama Stack distribution, with all the packages and configuration needed to run a Llama Stack server in a containerized environment.
6+
7+
You can see an overview of the APIs and Providers the image ships with in the table below.
8+
9+
| API | Provider |
10+
|-----|----------|
11+
| agents | inline::meta-reference |
12+
| datasetio | inline::localfs |
13+
| datasetio | remote::huggingface |
14+
| eval | remote::trustyai_lmeval |
15+
| files | inline::localfs |
16+
| inference | inline::sentence-transformers |
17+
| inference | remote::bedrock |
18+
| inference | remote::vllm |
19+
| inference | remote::watsonx |
20+
| safety | remote::trustyai_fms |
21+
| scoring | inline::basic |
22+
| scoring | inline::braintrust |
23+
| scoring | inline::llm-as-judge |
24+
| telemetry | inline::meta-reference |
25+
| tool_runtime | inline::rag-runtime |
26+
| tool_runtime | remote::brave-search |
27+
| tool_runtime | remote::model-context-protocol |
28+
| tool_runtime | remote::tavily-search |
29+
| vector_io | inline::milvus |
30+
| vector_io | remote::milvus |

scripts/gen_distro_docs.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python3
2+
3+
import yaml
4+
from pathlib import Path
5+
6+
7+
REPO_ROOT = Path(__file__).parent.parent
8+
9+
10+
def gen_distro_table(providers_data):
11+
# Start with table header
12+
table_lines = ["| API | Provider |", "|-----|----------|"]
13+
14+
# Create a list to collect all API-Provider pairs for sorting
15+
api_provider_pairs = []
16+
17+
# Iterate through each API type and its providers
18+
for api_name, provider_list in providers_data.items():
19+
if isinstance(provider_list, list):
20+
for provider in provider_list:
21+
if isinstance(provider, dict) and "provider_type" in provider:
22+
provider_type = provider["provider_type"]
23+
api_provider_pairs.append((api_name, provider_type))
24+
25+
# Sort first by API name, then by provider type
26+
api_provider_pairs.sort(key=lambda x: (x[0], x[1]))
27+
28+
# Add sorted pairs to table
29+
for api_name, provider_type in api_provider_pairs:
30+
table_lines.append(f"| {api_name} | {provider_type} |")
31+
32+
return "\n".join(table_lines)
33+
34+
35+
def gen_distro_docs():
36+
# define distro run.yaml and README.md paths
37+
run_yaml_path = REPO_ROOT / "distribution" / "run.yaml"
38+
readme_path = REPO_ROOT / "distribution" / "README.md"
39+
40+
# Check if run.yaml exists
41+
if not run_yaml_path.exists():
42+
print(f"Error: {run_yaml_path} not found")
43+
return 1
44+
45+
# header section
46+
header = """<!-- This file is automatically generated by scripts/gen_distro_doc.py - do not update manually -->
47+
48+
# Open Data Hub Llama Stack Distribution Image
49+
50+
This image contains the official Open Data Hub Llama Stack distribution, with all the packages and configuration needed to run a Llama Stack server in a containerized environment.
51+
52+
You can see an overview of the APIs and Providers the image ships with in the table below.
53+
54+
"""
55+
56+
try:
57+
# Load the run.yaml data
58+
with open(run_yaml_path, "r") as file:
59+
run_yaml_data = yaml.safe_load(file)
60+
61+
# Extract providers section
62+
providers = run_yaml_data.get("providers", {})
63+
64+
if not providers:
65+
print("Error: No providers found in run.yaml")
66+
return 1
67+
68+
# Generate the Markdown table
69+
table_content = gen_distro_table(providers)
70+
71+
# Write to README.md
72+
with open(readme_path, "w") as readme_file:
73+
readme_file.write(header + table_content + "\n")
74+
75+
print(f"Successfully generated {readme_path}")
76+
print(
77+
"Ensure you have checked-in any changes to the README to git, or the pre-commit check using this script will fail"
78+
)
79+
return 0
80+
81+
except Exception as e:
82+
print(f"Error: {e}")
83+
return 1
84+
85+
86+
if __name__ == "__main__":
87+
exit(gen_distro_docs())

0 commit comments

Comments
 (0)