mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 04:35:00 +00:00
wip: Added chat history logging to InputOutput class.
This commit is contained in:
parent
129f70dba8
commit
73b3151f6a
1 changed files with 36 additions and 3 deletions
|
@ -14,6 +14,7 @@ import time
|
||||||
import random
|
import random
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class FileContentCompleter(Completer):
|
class FileContentCompleter(Completer):
|
||||||
def __init__(self, fnames, commands):
|
def __init__(self, fnames, commands):
|
||||||
self.commands = commands
|
self.commands = commands
|
||||||
|
@ -56,7 +57,7 @@ class InputOutput:
|
||||||
self.pretty = pretty
|
self.pretty = pretty
|
||||||
self.yes = yes
|
self.yes = yes
|
||||||
self.input_history_file = input_history_file
|
self.input_history_file = input_history_file
|
||||||
self.chat_history_file = chat_history_file
|
self.chat_history_file = Path(chat_history_file)
|
||||||
|
|
||||||
if pretty:
|
if pretty:
|
||||||
self.console = Console()
|
self.console = Console()
|
||||||
|
@ -131,14 +132,31 @@ class InputOutput:
|
||||||
break
|
break
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
prefix = '####'
|
||||||
|
hist = inp.splitlines()
|
||||||
|
hist = f'\n{prefix} '.join(hist)
|
||||||
|
|
||||||
|
hist = f'''---
|
||||||
|
{prefix} {hist}'''
|
||||||
|
self.append_chat_history(hist)
|
||||||
|
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
## OUTPUT
|
## OUTPUT
|
||||||
|
|
||||||
def confirm_ask(self, question, default="y"):
|
def confirm_ask(self, question, default="y"):
|
||||||
if self.yes:
|
if self.yes:
|
||||||
return True
|
res = 'yes'
|
||||||
return prompt(question + " ", default=default)
|
else:
|
||||||
|
res = prompt(question + " ", default=default)
|
||||||
|
|
||||||
|
hist = f'*{question.strip()} {res}*'
|
||||||
|
self.append_chat_history(hist)
|
||||||
|
|
||||||
|
if not res:
|
||||||
|
return
|
||||||
|
return res.lower().startswith('y')
|
||||||
|
|
||||||
def prompt_ask(self, question, default=None):
|
def prompt_ask(self, question, default=None):
|
||||||
if self.yes:
|
if self.yes:
|
||||||
|
@ -146,9 +164,24 @@ class InputOutput:
|
||||||
return prompt(question + " ", default=default)
|
return prompt(question + " ", default=default)
|
||||||
|
|
||||||
def tool_error(self, message):
|
def tool_error(self, message):
|
||||||
|
if message.strip():
|
||||||
|
hist = f'*{message.strip()}*'
|
||||||
|
self.append_chat_history(hist)
|
||||||
|
|
||||||
message = Text(message)
|
message = Text(message)
|
||||||
self.console.print(message, style="red")
|
self.console.print(message, style="red")
|
||||||
|
|
||||||
def tool(self, *messages):
|
def tool(self, *messages):
|
||||||
|
if messages:
|
||||||
|
hist = ' '.join(messages)
|
||||||
|
hist = f'*{hist.strip()}*'
|
||||||
|
self.append_chat_history(hist)
|
||||||
|
|
||||||
messages = list(map(Text, messages))
|
messages = list(map(Text, messages))
|
||||||
self.console.print(*messages)
|
self.console.print(*messages)
|
||||||
|
|
||||||
|
def append_chat_history(self, text):
|
||||||
|
if not text.endswith('\n\n'):
|
||||||
|
text = text + '\n\n'
|
||||||
|
with self.chat_history_file.open("a") as f:
|
||||||
|
f.write(text)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue