Skip to content

Commit 6370198

Browse files
authored
Split llms-full.txt into llms-chat-apps.txt and llms-agents.txt (#463)
* custom 404 page * split llms-full.txt in two * Remove custom 404 changes, keep LLM documentation updates * macroscope feedback <3
1 parent e38923f commit 6370198

File tree

7 files changed

+23286
-8176
lines changed

7 files changed

+23286
-8176
lines changed

.github/workflows/generate-llms.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
paths:
88
- 'docs/**/*.md'
99
- 'docs/**/*.mdx'
10-
- '!llms/llms-full.txt'
10+
- '!llms/llms-*.txt'
1111

1212
jobs:
1313
build:
@@ -33,12 +33,15 @@ jobs:
3333
uses: peter-evans/create-pull-request@v5
3434
with:
3535
token: ${{ secrets.GITHUB_TOKEN }}
36-
commit-message: Update llms-full.txt
37-
title: Update llms-full.txt
36+
commit-message: Update LLM documentation files
37+
title: Update LLM documentation files
3838
body: |
39-
This PR updates the llms-full.txt file with the latest documentation.
40-
39+
This PR updates the LLM documentation files with the latest changes:
40+
- llms-chat-apps.txt (for chat app developers)
41+
- llms-agents.txt (for agent developers)
42+
- llms-full.txt (comprehensive documentation)
43+
4144
Automated PR created by GitHub Actions.
42-
branch: update-llms-full
45+
branch: update-llms-docs
4346
base: main
4447
delete-branch: true
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# Use XMTP documentation with AI coding assistants
22

3-
To make it easier to use AI coding agents to build with XMTP, you can find an `llms-full.txt` file at [https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-full.txt](https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-full.txt).
3+
To make it easier for you to build with XMTP using LLMs and coding assistants, we offer the following AI-ready documentation files.
44

5-
This `llms-full.txt` file includes all XMTP documentation in a single plain text file for easy parsing by AI agents.
5+
If you're using an AI coding assistant that allows custom context, you can upload or point to the appropriate file to enhance your development experience with XMTP. Using the file focused on your builder use case (chat apps or agents) typically provides better AI performance.
66

7-
If you're using an LLM tool that allows custom context, you can upload or point to `llms-full.txt` to enhance your AI coding experience with XMTP.
7+
## For building chat apps
8+
9+
Use `llms-chat-apps.txt`: [https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-chat-apps.txt](https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-chat-apps.txt)
10+
11+
Includes: Core messaging, content types, push notifications, user consent, protocol fundamentals, network operations, and funding information.
12+
13+
## For building agents
14+
15+
Use `llms-agents.txt`: [https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-agents.txt](https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-agents.txt)
16+
17+
Includes: Agent concepts, building and deploying agents, agent-specific content types, protocol fundamentals, network operations, and funding information.
18+
19+
## For comprehensive coverage
20+
21+
Use `llms-full.txt`: [https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-full.txt](https://raw.githubusercontent.com/xmtp/docs-xmtp-org/main/llms/llms-full.txt)
22+
23+
Includes: All documentation for chat apps, agents, protocol fundamentals, network operations, and funding information.

llms/generate_llms_full.py

Lines changed: 148 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,77 +13,179 @@ def extract_content_from_md(file_path):
1313
print(f"Error reading file {file_path}: {e}")
1414
return f"Error: Could not read content from {file_path}"
1515

16-
# Main function to generate the llms-full.txt file by combining all markdown files
17-
# from the specified directory
18-
def generate_llms_txt(directory, output_file='llms/llms-full.txt'): # Updated filename to llms-full.txt
16+
# Main function to generate LLM documentation files by combining markdown files
17+
# from specified subdirectories
18+
def generate_llms_txt(base_directory, subdirectories, output_file, title, description, include_sdk_instructions=True):
1919
processed_files = []
20-
20+
2121
# Make sure the output directory exists
2222
output_dir = os.path.dirname(output_file)
2323
if output_dir and not os.path.exists(output_dir):
2424
os.makedirs(output_dir)
25-
25+
2626
try:
2727
with open(output_file, 'w', encoding='utf-8') as llms_file:
2828
# Write the header and guidance at the top of the file
29-
llms_file.write("# XMTP Full Documentation\n\n")
30-
29+
llms_file.write(f"# {title}\n\n")
30+
3131
# Add timestamp
3232
current_time = datetime.now(timezone.utc)
3333
timestamp = current_time.strftime("Generated at %I:%M %p UTC / %B %d, %Y")
3434
llms_file.write(f"{timestamp}\n\n")
35-
llms_file.write("## Instructions for AI Tools\n\n")
36-
llms_file.write("This documentation includes code samples for multiple SDKs. Please use the code samples that correspond to the SDK you are working with:\n\n")
37-
llms_file.write("- For **xmtp-react-native**, use the code samples marked with `[React Native]`.\n")
38-
llms_file.write("- For **xmtp-android**, use the code samples marked with `[Kotlin]`.\n")
39-
llms_file.write("- For **xmtp-ios**, use the code samples marked with `[Swift]`.\n")
40-
llms_file.write("- For **xmtp-js** in a browser environment, use the code samples marked with `[Browser]`.\n")
41-
llms_file.write("- For **xmtp-js** in a Node.js environment, use the code samples marked with `[Node]`.\n\n")
42-
llms_file.write("Ensure that you select the correct code block to avoid compatibility issues.\n\n")
43-
44-
# Walk through all directories and files in the specified directory
45-
for root, _, files in os.walk(directory):
46-
for file in files:
47-
# Process only markdown files (.md and .mdx)
48-
if file.endswith(('.md', '.mdx')):
49-
file_path = os.path.join(root, file)
50-
# Get the path relative to the docs directory
51-
rel_path = os.path.relpath(file_path, directory)
52-
content = extract_content_from_md(file_path)
53-
54-
# Write the relative path as the header
55-
llms_file.write(f"## {rel_path}\n")
56-
llms_file.write(content)
57-
llms_file.write("\n\n")
58-
59-
processed_files.append(rel_path)
60-
35+
36+
# Add description
37+
llms_file.write(f"## About this file\n\n")
38+
llms_file.write(f"{description}\n\n")
39+
40+
# Add SDK instructions (optional)
41+
if include_sdk_instructions:
42+
llms_file.write("## Instructions for AI Tools\n\n")
43+
llms_file.write("This documentation includes code samples for multiple SDKs. Please use the code samples that correspond to the SDK you are working with:\n\n")
44+
llms_file.write("- For **xmtp-react-native**, use the code samples marked with `[React Native]`.\n")
45+
llms_file.write("- For **xmtp-android**, use the code samples marked with `[Kotlin]`.\n")
46+
llms_file.write("- For **xmtp-ios**, use the code samples marked with `[Swift]`.\n")
47+
llms_file.write("- For **xmtp-js** in a browser environment, use the code samples marked with `[Browser]`.\n")
48+
llms_file.write("- For **xmtp-js** in a Node.js environment, use the code samples marked with `[Node]`.\n\n")
49+
llms_file.write("Ensure that you select the correct code block to avoid compatibility issues.\n\n")
50+
51+
# Add table of contents
52+
llms_file.write("## Included Sections\n\n")
53+
for subdir in subdirectories:
54+
llms_file.write(f"- {subdir}\n")
55+
llms_file.write("\n---\n\n")
56+
57+
# Process each subdirectory
58+
for subdir in subdirectories:
59+
full_path = os.path.join(base_directory, subdir)
60+
61+
# Check if the subdirectory exists
62+
if not os.path.exists(full_path):
63+
print(f"Warning: Directory not found: {full_path}")
64+
continue
65+
66+
# Add section header
67+
llms_file.write(f"# Section: {subdir}\n\n")
68+
69+
# Walk through all directories and files in the subdirectory
70+
for root, _, files in os.walk(full_path):
71+
for file in sorted(files): # Sort files for consistent ordering
72+
# Process only markdown files (.md and .mdx)
73+
if file.endswith(('.md', '.mdx')):
74+
file_path = os.path.join(root, file)
75+
# Get the path relative to the base directory
76+
rel_path = os.path.relpath(file_path, base_directory)
77+
content = extract_content_from_md(file_path)
78+
if isinstance(content, str) and content.startswith("Error:"):
79+
print(f"Warning: Skipping {rel_path}: {content}")
80+
continue
81+
# Write the relative path as the header
82+
llms_file.write(f"## {rel_path}\n")
83+
llms_file.write(content)
84+
llms_file.write("\n\n")
85+
processed_files.append(rel_path)
86+
6187
# Add a summary at the end
6288
llms_file.write(f"# Summary\n\n")
63-
llms_file.write(f"This documentation contains {len(processed_files)} files.\n")
64-
89+
llms_file.write(f"This documentation contains {len(processed_files)} files from {len(subdirectories)} sections.\n")
90+
6591
print(f"Successfully processed {len(processed_files)} Markdown files into {output_file}")
6692
return processed_files
67-
93+
6894
except Exception as e:
6995
print(f"Error generating {output_file}: {e}")
7096
return []
7197

7298
# Script entry point
7399
if __name__ == "__main__":
74-
# Update the path to the docs directory
75-
docs_directory = 'docs'
76-
100+
# Base path to the docs directory
101+
docs_directory = 'docs/pages'
102+
77103
# Check if the docs directory exists
78104
if not os.path.isdir(docs_directory):
79105
print(f"Error: Directory not found: {docs_directory}")
80106
print("Make sure you're running this script from the correct location.")
81107
sys.exit(1)
82-
83-
# Generate the llms-full.txt file and get the list of processed files
84-
processed_files = generate_llms_txt(docs_directory, 'llms/llms-full.txt')
85-
86-
# Exit with error if no files were processed
87-
if not processed_files:
88-
print("Warning: No files were processed. Check the docs directory path.")
108+
109+
# Shared sections for both chat apps and agents
110+
shared_sections = [
111+
'protocol',
112+
'network',
113+
'fund-agents-apps'
114+
]
115+
116+
# Configuration for chat apps documentation
117+
chat_apps_config = {
118+
'subdirectories': ['chat-apps'] + shared_sections,
119+
'output_file': 'llms/llms-chat-apps.txt',
120+
'title': 'XMTP Documentation for Building Chat Applications',
121+
'description': 'This documentation is tailored for developers building chat apps with XMTP. It includes guides on core messaging, content types, push notifications, user consent, and more, along with protocol fundamentals, network operations, and funding information.'
122+
}
123+
124+
# Configuration for agents documentation
125+
agents_config = {
126+
'subdirectories': ['agents'] + shared_sections,
127+
'output_file': 'llms/llms-agents.txt',
128+
'title': 'XMTP Documentation for Building Agents',
129+
'description': 'This documentation is tailored for developers building agents with XMTP. It includes guides on agent concepts, building and deploying agents, content types, and integration patterns, along with protocol fundamentals, network operations, and funding information.'
130+
}
131+
132+
# Configuration for full documentation (everything)
133+
full_docs_config = {
134+
'subdirectories': ['chat-apps', 'agents'] + shared_sections,
135+
'output_file': 'llms/llms-full.txt',
136+
'title': 'XMTP Full Documentation',
137+
'description': 'This is the complete XMTP documentation including guides for building both chat apps and agents, along with protocol fundamentals, network operations, and funding information.'
138+
}
139+
140+
# Generate all three documentation files
141+
all_successful = True
142+
143+
print("Generating Chat Apps documentation...")
144+
chat_files = generate_llms_txt(
145+
docs_directory,
146+
chat_apps_config['subdirectories'],
147+
chat_apps_config['output_file'],
148+
chat_apps_config['title'],
149+
chat_apps_config['description']
150+
)
151+
152+
if not chat_files:
153+
print("Warning: No files were processed for chat apps documentation.")
154+
all_successful = False
155+
156+
print("\nGenerating Agents documentation...")
157+
agent_files = generate_llms_txt(
158+
docs_directory,
159+
agents_config['subdirectories'],
160+
agents_config['output_file'],
161+
agents_config['title'],
162+
agents_config['description'],
163+
include_sdk_instructions=False
164+
)
165+
166+
if not agent_files:
167+
print("Warning: No files were processed for agents documentation.")
168+
all_successful = False
169+
170+
print("\nGenerating Full documentation...")
171+
full_files = generate_llms_txt(
172+
docs_directory,
173+
full_docs_config['subdirectories'],
174+
full_docs_config['output_file'],
175+
full_docs_config['title'],
176+
full_docs_config['description']
177+
)
178+
179+
if not full_files:
180+
print("Warning: No files were processed for full documentation.")
181+
all_successful = False
182+
183+
# Exit with error if any generation failed
184+
if not all_successful:
185+
print("\nError: Some documentation files were not generated successfully.")
89186
sys.exit(1)
187+
188+
print(f"\n✓ Successfully generated all documentation files!")
189+
print(f" - {chat_apps_config['output_file']} ({len(chat_files)} files)")
190+
print(f" - {agents_config['output_file']} ({len(agent_files)} files)")
191+
print(f" - {full_docs_config['output_file']} ({len(full_files)} files)")

0 commit comments

Comments
 (0)