-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_llm_hook.py
More file actions
47 lines (36 loc) · 1.57 KB
/
generate_llm_hook.py
File metadata and controls
47 lines (36 loc) · 1.57 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
#!/usr/bin/env python3
"""
MkDocs hook to automatically generate LLM-friendly files during build.
This hook runs the generate_llm_files.py script during the MkDocs build process
to ensure llms.txt and llms-full.txt are always up to date.
"""
import subprocess
import sys
from pathlib import Path
def on_post_build(config, **kwargs):
"""
Hook that runs after MkDocs builds the site.
This generates the LLM files and copies them to the site directory
so they're available in the built documentation.
"""
try:
# Run the LLM file generation script
result = subprocess.run([
sys.executable, 'generate_llm_files.py'
], capture_output=True, text=True, cwd=config['docs_dir'] + '/..')
if result.returncode != 0:
print(f"Warning: Failed to generate LLM files: {result.stderr}")
return
print("✓ Generated LLM files successfully")
# Copy the generated files to the site directory
site_dir = Path(config['site_dir'])
root_dir = Path(config['docs_dir']).parent
for filename in ['llms.txt', 'llms-full.txt']:
src_file = root_dir / filename
dest_file = site_dir / filename
if src_file.exists():
dest_file.write_text(src_file.read_text(encoding='utf-8'), encoding='utf-8')
print(f"✓ Copied {filename} to site directory")
except Exception as e:
print(f"Warning: Error in LLM file generation hook: {e}")
# Don't fail the build, just warn