datasette-query-assistant by datasette
244 downloads this week Star
README source code
Query databases and tables with AI assistance
Early alpha.
Install this plugin in the same environment as Datasette.
datasette install datasette-query-assistant
Set the model ID to be used by this plugin by adding this to your Datasette configuration:
plugins:
datasette-query-assistant:
model: openai/gpt-4.1-mini
key_env_var: OPENAI_API_KEY
To use the openai/gpt-4.1-mini
model you'll need to install llm-openai-plugin
in addition to datasette-query-assistant
.
If the model needs an API key, set the key_env_var
to the name of an environment variable and ensure that environment variable is correctly set.
You can use any model that is available via an LLM plugin
Users with execute-sql
permission will gain a database action menu item for "Query this database with AI assistance" which will let them ask a question and be redirected to a commented SQL query that will hopefully answer it.
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-query-assistant
python3 -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
To re-generate the tests with refreshed examples from the API:
pytest -x --record-mode=rewrite --inline-snapshot=fix