Skip to content

Commit 0a23c94

Browse files
ci(docs): add automatic doc generation to pre-commit
Signed-off-by: Nathan Weinberg <nweinber@redhat.com>
1 parent 756fad8 commit 0a23c94

File tree

4 files changed

+126
-9
lines changed

4 files changed

+126
-9
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ 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+
always_run: true
68+
files: ^distribution/.*$
69+
additional_dependencies:
70+
- pyyaml==6.0.2

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
# Red Hat Distribution Build Instructions
1+
# ODH 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 [distribution directory](distribution).
6+
7+
To learn about how to modify/build the image yourself, see below.
8+
9+
## Build Instructions
10+
11+
### Prerequisites
612

713
- Python >=3.11
814
- `llama` CLI tool installed: `pip install llama-stack`
915
- Podman or Docker installed
1016

11-
## Generating the Containerfile
17+
### Generating the Containerfile
1218

1319
The Containerfile is auto-generated from a template. To generate it:
1420

@@ -23,26 +29,26 @@ This will:
2329
- Generate dependencies using `llama stack build`
2430
- Create a new `Containerfile` with the required dependencies
2531

26-
## Editing the Containerfile
32+
### Editing the Containerfile
2733

2834
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.
2935
NEVER edit the generated `Containerfile` manually.
3036

31-
## Building the Container Image
37+
### Building the Container Image
3238

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

35-
### Using Podman build image for x86_64
41+
#### Using Podman build image for x86_64
3642

3743
```bash
3844
podman build --platform linux/amd64 -f distribution/Containerfile -t rh .
3945
```
4046

41-
## Notes
47+
### Notes
4248

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

45-
## Push the image to a registry
51+
### Push the image to a registry
4652

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

distribution/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Open Data Hub Llama Stack Distribution Image
2+
3+
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.
4+
5+
You can see an overview of the APIs and Providers the image ships with in the table below.
6+
7+
| API | Provider |
8+
|-----|----------|
9+
| inference | remote::vllm |
10+
| inference | remote::bedrock |
11+
| inference | inline::sentence-transformers |
12+
| inference | remote::watsonx |
13+
| vector_io | inline::milvus |
14+
| vector_io | remote::milvus |
15+
| safety | remote::trustyai_fms |
16+
| agents | inline::meta-reference |
17+
| eval | remote::trustyai_lmeval |
18+
| datasetio | remote::huggingface |
19+
| datasetio | inline::localfs |
20+
| scoring | inline::basic |
21+
| scoring | inline::llm-as-judge |
22+
| scoring | inline::braintrust |
23+
| telemetry | inline::meta-reference |
24+
| tool_runtime | remote::brave-search |
25+
| tool_runtime | remote::tavily-search |
26+
| tool_runtime | inline::rag-runtime |
27+
| tool_runtime | remote::model-context-protocol |
28+
| files | inline::localfs |

scripts/gen_distro_docs.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
# Iterate through each API type and its providers
15+
for api_name, provider_list in providers_data.items():
16+
if isinstance(provider_list, list):
17+
for provider in provider_list:
18+
if isinstance(provider, dict) and "provider_type" in provider:
19+
provider_type = provider["provider_type"]
20+
table_lines.append(f"| {api_name} | {provider_type} |")
21+
22+
return "\n".join(table_lines)
23+
24+
25+
def gen_distro_docs():
26+
# define distro run.yaml and README.md paths
27+
run_yaml_path = REPO_ROOT / "distribution" / "run.yaml"
28+
readme_path = REPO_ROOT / "distribution" / "README.md"
29+
30+
# Check if run.yaml exists
31+
if not run_yaml_path.exists():
32+
print(f"Error: {run_yaml_path} not found")
33+
return 1
34+
35+
# header section
36+
header = """# Open Data Hub Llama Stack Distribution Image
37+
38+
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.
39+
40+
You can see an overview of the APIs and Providers the image ships with in the table below.
41+
42+
"""
43+
44+
try:
45+
# Load the run.yaml data
46+
with open(run_yaml_path, "r") as file:
47+
run_yaml_data = yaml.safe_load(file)
48+
49+
# Extract providers section
50+
providers = run_yaml_data.get("providers", {})
51+
52+
if not providers:
53+
print("Error: No providers found in run.yaml")
54+
return 1
55+
56+
# Generate the Markdown table
57+
table_content = gen_distro_table(providers)
58+
59+
# Write to README.md
60+
with open(readme_path, "w") as readme_file:
61+
readme_file.write(header + table_content + "\n")
62+
63+
print(f"Successfully generated {readme_path}")
64+
return 0
65+
66+
except Exception as e:
67+
print(f"Error: {e}")
68+
return 1
69+
70+
71+
if __name__ == "__main__":
72+
exit(gen_distro_docs())

0 commit comments

Comments
 (0)