Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chat History Storage and Datasette Integration. closes #1859 #1860

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.db
env/
.DS_Store
.vscode/
aider.code-workspace
Expand All @@ -11,4 +13,4 @@ _site
.jekyll-cache/
.jekyll-metadata
aider/__version__.py
.venv/
.venv/
7 changes: 5 additions & 2 deletions aider/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ def get_images_message(self):

def run_stream(self, user_message):
self.io.user_input(user_message)
self.io.append_chat_history(user_message, role="user")
self.init_before_message()
yield from self.send_message(user_message)

Expand Down Expand Up @@ -1432,11 +1433,13 @@ def send(self, messages, model=None, functions=None):

if self.partial_response_content:
self.io.ai_output(self.partial_response_content)
self.io.append_chat_history(self.partial_response_content, role="assistant")
elif self.partial_response_function_call:
# TODO: push this into subclasses
args = self.parse_partial_args()
if args:
self.io.ai_output(json.dumps(args, indent=4))
content = json.dumps(args, indent=4)
self.io.ai_output(content)
self.io.append_chat_history(content, role="assistant")

self.calculate_and_show_tokens_and_cost(messages, completion)

Expand Down
59 changes: 58 additions & 1 deletion aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from prompt_toolkit.completion import Completion, PathCompleter
from prompt_toolkit.document import Document

from aider import models, prompts, voice
from aider import models, prompts, utils, voice
from aider.format_settings import format_settings
from aider.help import Help, install_help_extra
from aider.llm import litellm
Expand Down Expand Up @@ -1246,6 +1246,63 @@ def cmd_report(self, args):

report_github_issue(issue_text, title=title, confirm=False)

def cmd_datasette(self, args):
"Launch or stop Datasette with the current chat history"
if not utils.check_pip_install_extra(
self.io,
"datasette",
"You need to install Datasette and its query assistant",
["datasette", "datasette-query-assistant"],
):
return

if not self.io.use_sqlite:
self.io.tool_error(
"SQLite integration is not enabled. Please enable it to use Datasette."
)
return

db_path = self.io.chat_history_file.with_suffix(".db")
if not db_path.exists():
self.io.tool_error("Chat history database not found.")
return

datasette_process = getattr(self.coder, "datasette_process", None)
if datasette_process and datasette_process.poll() is None:
datasette_process.terminate()
datasette_process.wait()
self.coder.datasette_process = None
self.io.tool_output("Stopped Datasette.")
return

try:
datasette_process = subprocess.Popen(
["datasette", str(db_path)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
self.coder.datasette_process = datasette_process
self.io.tool_output("Launched Datasette. Access it at http://localhost:8001/")
self.io.tool_output(
"For help, visit: https://docs.datasette.io/en/1.0a14/getting_started.html"
)
except Exception as e:
self.io.tool_error(f"Failed to launch Datasette: {str(e)}")

def cmd_search(self, args):
"Search the chat history using full-text search"
if not args.strip():
self.io.tool_error("Please provide a search query.")
return

results = self.io.search_chat_history(args.strip())
if not results:
self.io.tool_output("No results found.")
return

self.io.tool_output(f"Search results for '{args.strip()}':")
for timestamp, role, content in results:
self.io.tool_output(f"\n[{timestamp}] {role.upper()}:")
self.io.tool_output(content.strip())


def expand_subdir(file_path):
if file_path.is_file():
Expand Down
Loading
Loading