Log chats to database for enhanced interaction
Issue
It would be handy to log chats to a database rather than just save a large .md file. I was inspired by this tool, which logs all LLM chats to sqlite and then allows you to explore the logs in your browser.
this can add a lot of really nice features "for free", through the use of SQL queries in datasette.
- easily track costs e.g. across a day, a repo.
- full text search of chat history, could add vector search too. Minimises costs; search history instead of asking again.
- datasette plugins allow many additional features, e.g AI generated SQL queries to enable natural language queries to generate SQL to search your chat
Using datasette is a good solution, or perhaps a future version of aider might implement some of those features internally.
added PR #1860
This would be a perfect first plugin if aider ever gets a plugin system, otherwise I think the current markdown file log works super fine.
The only downside is that the markdown log is for all aider sessions combined, but that can be worked around with a Bash/shell alias. See this post I copied from the Discord ->
Here is a cute Bash alias for aider: It will create separate chat/input history files for each aider session in a .aider.history folder with a timestamp and the current branch name of the git repository, to make it much easier to look things up later. If no git repository is present, default gets used as the branch name.
Example when run:
aider --input-history-file .aider.history/feature-20240910_1213.input.md --chat-history-file .aider.history/feature-20240910_1213.chat.md
Bash alias:
alias aider='mkdir -p .aider.history ; branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "default"); timestamp=$(date "+%Y%m%d_%H%M"); aider --input-history-file ".aider.history/$branch-$timestamp.input.md" --chat-history-file ".aider.history/$branch-$timestamp.chat.md"'
This makes it also possible to automatically clean out old sessions, preventing endless growing history files (which are also a pain to search/lookup).
Downside: No more global input history, every session starts fresh with an empty one (no going back). This could be changed though, just remove the --input-history-file part from the alias.
Slight modification to @fry69 's helpful bash alias. The following version will support Git branches if they have /s in them:
alias aider='branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "default"); timestamp=$(date "+%Y%m%d_%H%M"); mkdir -p ".aider.history/$(dirname "$branch")" ; aider --input-history-file ".aider.history/$branch-$timestamp.input.md" --chat-history-file ".aider.history/$branch-$timestamp.chat.md"'