Skip to main content

No project description provided

Project description

sphinx-llm

The sphinx-llm package includes a collection of extensions for working with LLMs.

There are two categories of tools in this package:

  • Enabling LLMs and agents to consume your docs - This is useful when you want your project to be well indexed and represented in LLMs when users ask about projects in your domain.
  • Leveraging LLMs to generate content dynamically during the Sphinx build - This is useful for generating static content that gets baked into the documentation. It it not intended to provide an interactive chat service in your documentation.

Installation

pip install sphinx-llm

# For extensions that use LLMs to generate text
pip install sphinx-llm[gen]

Extensions

llms.txt Support

The sphinx_llm.txt extension automatically generates markdown files for consumption by LLMs following the llms.txt standard alongside HTML files during the Sphinx build process.

The llms.txt standard describes how you can provide documentation in a way that can be easily consumed by LLMs, either during model training or by agents at inference time when using tools that gather context from the web. The standard describes that your documentation sitemap should be provided in markdown in llms.txt and then the entire documentation should be provided in markdown via a single file called llms-full.txt. Additionally each individual page on your website should also have a markdown version of the page at the same URL with an additional .md extension.

To use the extension add it to your conf.py:

# conf.py
# ...

extensions = [
    "sphinx_llm.txt",
]

When you build your documentation with sphinx-build (or make html), the extension will:

  1. Find all HTML files generated in the output directory
  2. Convert each HTML file to markdown format
  3. Save the markdown files with the same name plus an extra .md extension
  4. Concatenates all generated markdown into a single llms-full.txt file

For example, if your build generates:

  • _build/html/index.html
  • _build/html/apples.html

The extension will also create:

  • _build/html/index.html.md
  • _build/html/apples.html.md
  • _build/html/llms-full.txt

Note: This extension only works with HTML builders (like html and dirhtml).

Docref

The sphinx_llm.docref extension adds a directive for summarising and referencing other pages in your documentation. Instead of just linking to a page the extension will generate a summary of the page being linked to and include that too.

To use this extension you need to have ollama running.

If you have a GPU then generation will be much faster, but it is optional. See the GitHub Actions for an example of using it in CI.

To use the extension add it to your conf.py.

# conf.py
# ...

extensions = [
    "sphinx_llm.docref",
]

Then use the docref directive in your documents to reference other documents.

Testing page
============


.. docref:: apples
   
   Summary of apples page.

Then when you run sphinx-build (or make html) a summary will be generated and your source file will be updated too.

Testing page
============


.. docref:: apples
   :hash: 31ec12a54205539af3cde39b254ec766
   :model: llama3.2:3b
   
   Feeding apples to a friendly pig involves selecting ripe, pesticide-free apples, washing them thoroughly, cutting into manageable pieces, introducing them calmly, monitoring the pig's reaction, and cleaning up afterwards.

A hash of the referenced document is included to avoid generating summaries unnecessarily. But if the referenced page changes the summary will be regenerated.

You can also modify the summary if you need to clean up the language generated, and as long as the hash still matches the file it will be used.

Building the docs

Try it out yourself by building the example documentation.

uv run --dev sphinx-autobuild docs/source docs/build/html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_llm-0.1.2.tar.gz (253.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_llm-0.1.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_llm-0.1.2.tar.gz.

File metadata

  • Download URL: sphinx_llm-0.1.2.tar.gz
  • Upload date:
  • Size: 253.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for sphinx_llm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 47d4dca8b1022e2b12758b41b7b535f9c4287399e9a3ad1f4bf2c01f178a0121
MD5 6fc17fc4c4d57b5fcd636cb343c42890
BLAKE2b-256 d23da7a0832421f37b404e84b9ef526ba8be9ef18e098e0a3dd9bac58a9b720d

See more details on using hashes here.

File details

Details for the file sphinx_llm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sphinx_llm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for sphinx_llm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c2209c31db7c892f17440a9963a7e79e6a6e04f1a7a503797b0d22aae189273
MD5 007289f3dc2d2e2f5c8be5ff955994f9
BLAKE2b-256 66274b68e9d0e87a2866c14b721d3b9acce3211c3788a9b4c66cf18f4b11346d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page