Aider-AI / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
22.49k stars 2.09k forks source link

Log chats to database for enhanced interaction #1859

Open lockmeister opened 1 month ago

lockmeister commented 1 month ago

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.

Using datasette is a good solution, or perhaps a future version of aider might implement some of those features internally.

lockmeister commented 1 month ago

added PR #1860

fry69 commented 1 month ago

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.