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
- A website widget with your site on its Allowed origins list, for example
https://yourproject.readthedocs.io or your custom domain. You need the widget id and public key from its snippet.
Open conf.py
It is at the root of your Sphinx project, often inside docs/.
Add the widget to html_js_files
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.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 Ask AI button appears in the bottom-right corner. 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.