Sphinx adds every entry in html_js_files to every page, with the attributes you give it. You add the widget there. You need Sphinx 1.8 or later.

Before you start

  • Your website widget. Kelu makes one for you when you create a knowledge base. Its Install tab shows these steps with your widget id and key already in the code.
  • Your site on the widget’s Sites it works on list (Install tab), for example https://yourproject.readthedocs.io or your custom domain.

Add the widget

1

Open conf.py

It is at the root of your Sphinx project, often inside docs/.
2

Add the widget to html_js_files

conf.py
html_js_files = [
    (
        "https://widget.kelu.dev/kelu-widget.js",
        {
            "async": "async",
            "data-widget-id": "YOUR_WIDGET_ID",
            "data-client-key": "kl_pk_...",
        },
    ),
]
Replace YOUR_WIDGET_ID and kl_pk_... with the values from your widget’s snippet. If html_js_files already exists, add the tuple to it.
3

Build, then deploy

Run make html, then python -m http.server -d _build/html and open http://localhost:8000 to check it. Then deploy your site as usual.

Check it works

Open any page. A round icon button appears in the bottom-right corner, with the tooltip Ask AI. Ask a question and check that the answer lists its Sources. Nothing there? See Troubleshooting.
On Read the Docs, if some keys do not type in the widget, turn off the Hotkeys and Visual diff addons in your project’s settings.