datasette / datasette-query-assistant

Query databases and tables with AI assistance
Apache License 2.0
14 stars 2 forks source link

Initial prototype #1

Closed simonw closed 5 months ago

simonw commented 5 months ago

Goal is to have a database action menu item which takes the user to a form where they ask a question.

The question is passed to an LLM (starting with Claude 3 Haiku) along with the DB schema and they are redirect to the resulting SQL query answer.

Long term I want lots of explanations. For the moment I'll go with "include extensive SQL comments".

simonw commented 5 months ago

Idea: table action menu item too, which only includes the current table and any tables in its foreign key graph rather than the full schema.

I'd like you to be able to toggle tables on and off as well.

simonw commented 5 months ago

Neat trick: run explain select ... and see if there are any errors, then round-trip those errors back through the model up to X times to see if we can get a query that works.

simonw commented 5 months ago

Not bad for a first prototype!

demo

simonw commented 5 months ago

Claude is a bit fiddly about order - you HAVE to go user / assistant / user - but this worked: https://github.com/datasette/datasette-assistant/blob/05f32011d7ef3cab854d444302bcca332bf575f7/datasette_assistant/__init__.py#L25-L31