Chapter: README (docs/README.md)
AdalFlow Documentation Guide
Content Overview
- AdalFlow Documentation Guide
Introduction
AdalFlow uses Sphinx and reStructuredText for generating project documentation. Sphinx reads configurations from a Python script (conf.py), pulls documentation from comments in the code (via the autodoc extension), and organizes content through .rst files.
How the Documentation Works
- Configuration: Managed via
conf.py. - Automatic Documentation: Generated from docstrings using
autodoc. - Content Organization: Structured through
.rstfiles and the table of contents defined inindex.rst.
This guide will walk you through setting up, building, and contributing to the AdalFlow documentation.
Prerequisites
Before you begin, ensure you have the following installed:
Poetry: For dependency management. Install it with:
bashpip install poetryOptional Tools:
pandocfor converting Markdown to reStructuredText.- A modern browser for viewing documentation.
Setup
1. Clone the Repository
Clone the AdalFlow GitHub repository:
git clone https://github.com/SylphAI-Inc/AdalFlow.git
cd AdalFlow2. Install Dependencies
Install all necessary dependencies using poetry:
poetry installIf you encounter issues with poetry, ensure it is up-to-date by reinstalling:
pip install --upgrade poetryNote: Be sure to run these commands from the root level of the project.
3. Verify Setup
Ensure all dependencies are installed correctly:
poetry checkFile Structure
**conf.py**
The docs/source/conf.py controls the configurations used by Sphinx to build the documentation, including the project-related information, sphinx extensions, templates configuration, HTML theme, patterns to exclude, language configuration, project path setup, etc.
**index.rst**
The docs/source/index.rst is the root document for Sphinx-generated documentation ("homepage" for the documentation site). It includes the toctree that defines the documentation hierarchical structure (sections/chapters). It also links to other .rst files that users can navigate through.
For example, in the index.rst, the :caption: Get Started corresponds to the section name of the documentation site. installation and introduction are the detailed pages.
.. toctree::
:glob:
:maxdepth: 1
:caption: Get Started
get_started/installation
get_started/introduction**Existing Sections**
Existing sections include:
get_started/: Includes installation and AdalFlow in 10 minutestutorials/: Includes our main tutorialsuse_cases/: Includes the use cases of AdalFlow that will be added in the future and which accepts community contributionsapis/: All the source-code-related documents will be included in this directory
Editing and Updating Documentation
Updating Docstrings in Source Code
Most of the documentation is automatically generated from code comments using the autodoc extension. To update:
- Edit the docstrings in your source code.
- Rebuild the documentation (see Building the Documentation).
Note: Ensure that your docstrings follow the reStructuredText format for proper rendering.
Adding New Code and Docstrings
When you add new modules or code to the project, it's essential to generate corresponding .rst files to include them in the documentation. Here's how to do it:
Ensure Proper Structure:
- If your new module is a folder, it should contain an
__init__.pyfile to be recognized as a package. - Write comprehensive docstrings for your new code to leverage the
autodocextension effectively.
- If your new module is a folder, it should contain an
Generate
.rstFiles Usingsphinx-apidoc:Use the
sphinx-apidoccommand to automatically generate.rstfiles for your new modules:bashsphinx-apidoc [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN โฆ]Example:
While located in the root directory of your project, run the following command to generate
.rstfiles for theuse_casesmodule, excluding any files or directories with "test" in their names:bashsphinx-apidoc --force -o docs/source/tutorials ./use_cases "*test*"--force: Overwrites any existing.rstfiles in the output directory. This is safe as long as you haven't made manual edits to these.rstfiles.-o docs/source/tutorials: Specifies the directory where the.rstfiles will be generated../use_cases: Path to the module or package to document."*test*": Excludes any files or directories with "test" in their names.
Caution: The
--forceflag will overwrite existing.rstfiles in the specified output directory. Ensure that you haven't made manual edits to these files that you wish to preserve. If you have custom.rstfiles, consider backing them up or omitting the--forceflag.Update
index.rstto Include New Sections:After generating the
.rstfiles, update theindex.rstto include the new documentation sections. For example:rst.. toctree:: :glob: :maxdepth: 1 :caption: Tutorials tutorials/use_casesThis ensures the new module is linked in the documentation's table of contents.
Rebuild the Documentation:
After adding new docstrings and generating
.rstfiles, rebuild the documentation to see the updatesSummary of Steps When Adding New Code with Docstrings:
- Add the new code/module with proper docstrings.
- Generate
.rstfiles usingsphinx-apidoc. - Update
index.rstto include new sections. - Rebuild the documentation to reflect changes.
Building the Documentation
Steps to Build
Navigate to the
docsDirectory:bashcd docsClean Previous Builds:
Remove previous build artifacts to ensure a fresh build.
bashmake cleanBuild the Documentation:
Generate the HTML documentation.
bashmake html(Optional) Build with Verbose Output:
For more detailed build logs, useful for debugging.
bashsphinx-build -b html source build -v
Quick Start
For users who prefer straightforward commands without additional options:
cd docs
make htmlAfter the build completes, open the documentation:
macOS:
bashopen build/html/index.htmlLinux:
bashxdg-open build/html/index.htmlWindows:
Manually open the
index.htmlfile in your preferred browser.
Viewing the Documentation
After building, the HTML files will be available in docs/build/html. Open index.html in your browser to view the documentation.
Handling Browser Restrictions on Local Resources:
Some browsers restrict loading local resources like CSS for security reasons. In such cases, use a local server to serve the files:
cd docs/build/html
python -m http.serverVisit http://127.0.0.1:8000/ in your browser to view the documentation.
Testing the Documentation
To ensure the documentation builds correctly without errors or warnings, run:
sphinx-build -n -W --keep-going source build-n: Runs Sphinx in nit-picky mode to catch missing references.-W: Treats warnings as errors, causing the build to fail if any warnings are present.--keep-going: Continues the build as much as possible after encountering errors.
Recommendation: Fix any issues reported by this command before committing your changes to maintain documentation quality.
Contributing
Git Workflow
To maintain a clean repository, exclude unnecessary files from commits. Specifically, avoid committing the docs/build directory, as documentation builds are dynamic and can be regenerated locally.
Example .gitignore:
# Ignore build files
docs/build/
*.pyc
__pycache__/- Commit Only Necessary Files:
- Source files (
.rst,.py, etc.) - Configuration files (
conf.py,Makefile,pyproject.toml, etc.)
- Source files (
- Exclude:
docs/build/: Generated HTML files.- Compiled Python files (
*.pyc,__pycache__/).
Directory Structure
Ensure the project follows this structure:
AdalFlow/
โโโ docs/
โ โโโ apis/
โ โ โโโ core/
โ โ โ โโโ core.module1.rst
โ โ โ โโโ core.module2.rst
โ โ โโโ components/
โ โ โ โโโ components.module1.rst
โ โ โ โโโ components.module2.rst
โ โโโ build/
โ โ โโโ html/
โ โ โ โโโ _static/
โ โ โ โโโ _templates/
โ โ โ โโโ index.html
โ โ โ โโโ core/
โ โ โ โ โโโ core.module1.html
โ โ โ โ โโโ core.module2.html
โ โ โ โโโ components/
โ โ โ โ โโโ components.module1.html
โ โ โ โ โโโ components.module2.html
โ โโโ _static/
โ โโโ _templates/
โ โโโ conf.py
โ โโโ index.rst
โ โโโ Makefile
โ โโโ pyproject.toml
โ โโโ poetry.lockNote: The build/ directory contains generated files and should not be manually edited or committed.
Optional Tools
If you want to add any written files such as README.md to the documentation, there is an easy way to transform the files to .rst files using Pandoc.
Convert Markdown to reStructuredText
To convert .md files (e.g., README.md) to .rst:
Install
pandoc:bashbrew install pandocFor non-Homebrew users, refer to Pandoc's installation guide.
Run the Conversion:
Conversion Syntax:
bashpandoc -s <input.md> -o <path/to/target.rst>Example:
This command will take content from
README.mdand create anintroduction.rstfile in the specified directory.bashpandoc -s README.md -o docs/source/get_started/introduction.rstRebuild the Documentation:
After converting, rebuild the documentation to include the new
.rstfiles.bashcd docs make clean make html
Note: Ensure that the converted .rst files are correctly linked in your index.rst or appropriate parent .rst files.