-
Notifications
You must be signed in to change notification settings - Fork 1
Generate llms-full.txt by using gitingest script
#1418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josh-wong
merged 5 commits into
main
from
generate-llms-full.txt-by-using-gitingest-script
Aug 7, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e74b882
Add script to generate `llms-full.txt` by using gitingest
josh-wong 60d25c3
Add `generate-llms-full` script to build process
josh-wong ee6eb29
Disable `generateLLMsFullTxt` for `docusaurus-plugin-llms`
josh-wong f273946
Add README for `generate-llms-full.py` script
josh-wong d6474dc
Apply suggestions from Copilot and Gemini review
josh-wong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Create `llms-full.txt` by Using the `generate-llms-full.py` Script | ||
|
|
||
| The `generate-llms-full.py` script generates an `llms-full.txt` file when the Docusaurus site is built. | ||
|
|
||
| > [!CAUTION] | ||
| > | ||
| > If this script stops working, it's because [gitingest](https://github.com/coderamp-labs/gitingest) is either down or has limited its API usage. If that happens, we'll need to find another way or host gitingest ourselves and provide it with an API key from an AI language model provider (OpenAI, Claude, etc.) to generate the `llms-full.txt` file. | ||
|
|
||
| ## Why do we need this script? | ||
|
|
||
| The `docusaurus-plugin-llms` plugin can generate a `llms-full.txt` file, the file doesn't include front-matter metadata. Currently, this seems to be the expected behavior for the `llms.txt` standard. | ||
|
|
||
| However, we need to be able to tell AI language models when our documentation applies to only specific editions, which is already specified in `tags` in the front-matter properties of each Markdown file. | ||
|
|
||
| By using [gitingest](https://github.com/coderamp-labs/gitingest), we can generate a `llms-full.txt` that includes front-matter data as well as a directory tree within `llms-full.txt` to provide AI language models with better context into our documentation, particularly front-matter metadata (like edition tags) and documentation navigation. | ||
|
|
||
| ## Usage | ||
|
|
||
| The `generate-llms-full` script runs when the Docusaurus site is built: | ||
|
|
||
| ```shell | ||
| npm run generate-llms-full | ||
| ``` | ||
|
|
||
| You should rarely have to run the following Python script directly, unless you want to do testing: | ||
|
|
||
| ```shell | ||
| python scripts/generate-llms-full.py | ||
| ``` | ||
|
|
||
| ### Requirements | ||
|
|
||
| - Python 3.8+ | ||
| - gitingest package (automatically installed by using `pip` if not present) | ||
|
|
||
| ### What the `generate-llms-full.py` script does | ||
|
|
||
| 1. Uses gitingest to analyze the `docs` directory. | ||
| 2. Automatically installs gitingest if not already available. | ||
| 3. Includes only .mdx documentation files (`docs/*.mdx`, `docs/**/*.mdx`, and `src/components/en-us`). | ||
| 4. Focuses on the latest version of English documentation. | ||
| 5. Excludes build artifacts, node_modules, and other irrelevant files. | ||
| 6. Generates a comprehensive AI-friendly text digest. | ||
| 7. Adds a custom header for ScalarDB documentation context. | ||
| 8. Outputs to `build/llms-full.txt`. | ||
|
|
||
| ### Configuration | ||
|
|
||
| The script includes these file patterns: | ||
|
|
||
| - **Include:** `docs/*.mdx`, `docs/**/*.mdx`, `src/components/en-us/*.mdx`, `src/components/en-us/**/*.mdx` (only latest English docs) | ||
| - **Exclude:** `node_modules/*`, `.git/*`, `build/*`, `*.log` | ||
| - **Max file size:** 100KB per file | ||
|
|
||
| ### Benefits over `docusaurus-plugin-llms` | ||
|
|
||
| - Better repository understanding and context | ||
| - More comprehensive file inclusion | ||
| - Optimized format for AI language model consumption | ||
| - Active maintenance and updates | ||
| - Superior pattern matching and filtering |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Generate llms-full.txt by using gitingest instead of docusaurus-plugin-llms | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Add the project root to the Python path. | ||
| project_root = Path(__file__).parent.parent | ||
| sys.path.insert(0, str(project_root)) | ||
josh-wong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def install_gitingest(): | ||
| """Install gitingest package using pip.""" | ||
| try: | ||
| print("📦 Installing gitingest...") | ||
| subprocess.check_call([sys.executable, "-m", "pip", "install", "gitingest"]) | ||
| print("✅ gitingest installed successfully") | ||
| return True | ||
| except subprocess.CalledProcessError as e: | ||
| print(f"❌ Failed to install gitingest: {e}") | ||
| return False | ||
|
|
||
| # Try to import gitingest, install if not available | ||
| try: | ||
| from gitingest import ingest_async | ||
| except ImportError: | ||
| print("⚠️ gitingest not found, attempting to install...") | ||
| if install_gitingest(): | ||
| try: | ||
| from gitingest import ingest_async | ||
| print("✅ gitingest imported successfully after installation") | ||
| except ImportError: | ||
| print("❌ Failed to import gitingest even after installation") | ||
| print("Manual installation may be required:") | ||
| print(" pip install gitingest") | ||
| print(" # or") | ||
| print(" pipx install gitingest") | ||
| sys.exit(1) | ||
| else: | ||
| print("❌ gitingest installation failed") | ||
| print("Manual installation required:") | ||
| print(" pip install gitingest") | ||
| print(" # or") | ||
| print(" pipx install gitingest") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| async def generate_llms_full(): | ||
| """Generate llms-full.txt by using gitingest.""" | ||
| try: | ||
| print("Generating llms-full.txt by using gitingest...") | ||
|
|
||
| # Current repository path | ||
| repo_path = Path(__file__).parent.parent | ||
| build_dir = repo_path / "build" | ||
| build_dir.mkdir(exist_ok=True) | ||
|
|
||
| # Configure the gitingest parameters. | ||
| include_patterns = { | ||
| "docs/*.mdx", "docs/**/*.mdx", "src/components/en-us/*.mdx", "src/components/en-us/**/*.mdx" | ||
| } | ||
|
|
||
| exclude_patterns = { | ||
| "node_modules/*", ".git/*", "build/*", | ||
| "*.log", ".next/*", "dist/*", ".docusaurus/*" | ||
| } | ||
josh-wong marked this conversation as resolved.
Show resolved
Hide resolved
josh-wong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Generate content by using gitingest. | ||
| summary, tree, content = await ingest_async( | ||
| str(repo_path), | ||
| max_file_size=102400, # 100KB max file size | ||
| include_patterns=include_patterns, | ||
| exclude_patterns=exclude_patterns, | ||
| include_gitignored=False | ||
| ) | ||
|
|
||
| # Create a header that matches your current format. | ||
| header = """# ScalarDB Documentation - Full Repository Context | ||
| # Generated by using GitIngest for AI/LLM consumption | ||
| # Cloud-native universal transaction manager | ||
| # Website: https://scalardb.scalar-labs.com | ||
| """ | ||
josh-wong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
josh-wong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Combine all sections. | ||
| full_content = header + summary + "\n\n" + tree + "\n\n" + content | ||
|
|
||
| # Write to the build directory. | ||
| output_path = build_dir / "llms-full.txt" | ||
| with open(output_path, 'w', encoding='utf-8') as f: | ||
| f.write(full_content) | ||
|
|
||
| print(f"✅ llms-full.txt generated successfully at {output_path}") | ||
| print(f"📊 Summary: {len(full_content)} characters, estimated tokens: {len(full_content.split())}") | ||
|
|
||
| except Exception as error: | ||
| print(f"❌ Error generating llms-full.txt: {error}") | ||
| sys.exit(1) | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(generate_llms_full()) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.