mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
Added support for logging LLM history to a specified file.
This commit is contained in:
parent
8896909e19
commit
e6e360a4ef
4 changed files with 27 additions and 12 deletions
|
@ -20,11 +20,17 @@ def get_parser(default_config_files, git_root):
|
||||||
auto_env_var_prefix="AIDER_",
|
auto_env_var_prefix="AIDER_",
|
||||||
)
|
)
|
||||||
group = parser.add_argument_group("Main")
|
group = parser.add_argument_group("Main")
|
||||||
|
group.add_argument(
|
||||||
|
"--llm-history-file",
|
||||||
|
metavar="LLM_HISTORY_FILE",
|
||||||
|
default=".aider.llm.history",
|
||||||
|
help="Specify the LLM history file (default: .aider.llm.history)",
|
||||||
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"files",
|
"files",
|
||||||
metavar="FILE",
|
metavar="FILE",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="files to edit with an LLM (optional)",
|
help="files to edit with an LLM (optional)"
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--openai-api-key",
|
"--openai-api-key",
|
||||||
|
|
|
@ -784,10 +784,7 @@ class Coder:
|
||||||
|
|
||||||
messages = self.format_messages()
|
messages = self.format_messages()
|
||||||
|
|
||||||
timestamp = datetime.datetime.now().isoformat(timespec='seconds')
|
self.io.log_llm_history("TO LLM", format_messages(messages))
|
||||||
with open('.aider.llm.history', 'a') as log_file:
|
|
||||||
log_file.write(f"TO LLM {timestamp}\n")
|
|
||||||
log_file.write(format_messages(messages) + "\n")
|
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
utils.show_messages(messages, functions=self.functions)
|
utils.show_messages(messages, functions=self.functions)
|
||||||
|
@ -808,6 +805,9 @@ class Coder:
|
||||||
exhausted = True
|
exhausted = True
|
||||||
else:
|
else:
|
||||||
raise err
|
raise err
|
||||||
|
except Exception as err:
|
||||||
|
self.io.tool_error(f"Unexpected error: {err}")
|
||||||
|
return
|
||||||
|
|
||||||
if exhausted:
|
if exhausted:
|
||||||
self.num_exhausted_context_windows += 1
|
self.num_exhausted_context_windows += 1
|
||||||
|
@ -831,10 +831,7 @@ class Coder:
|
||||||
|
|
||||||
self.io.tool_output()
|
self.io.tool_output()
|
||||||
|
|
||||||
timestamp = datetime.datetime.now().isoformat(timespec='seconds')
|
self.io.log_llm_history("LLM RESPONSE", format_content("ASSISTANT", content))
|
||||||
with open('.aider.llm.history', 'a') as log_file:
|
|
||||||
log_file.write(f"LLM RESPONSE {timestamp}\n")
|
|
||||||
log_file.write(format_content("ASSISTANT", content) + "\n")
|
|
||||||
|
|
||||||
if interrupted:
|
if interrupted:
|
||||||
content += "\n^C KeyboardInterrupt"
|
content += "\n^C KeyboardInterrupt"
|
||||||
|
|
17
aider/io.py
17
aider/io.py
|
@ -106,6 +106,7 @@ class InputOutput:
|
||||||
tool_error_color="red",
|
tool_error_color="red",
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
|
llm_history_file=None,
|
||||||
):
|
):
|
||||||
no_color = os.environ.get("NO_COLOR")
|
no_color = os.environ.get("NO_COLOR")
|
||||||
if no_color is not None and no_color != "":
|
if no_color is not None and no_color != "":
|
||||||
|
@ -125,6 +126,7 @@ class InputOutput:
|
||||||
self.yes = yes
|
self.yes = yes
|
||||||
|
|
||||||
self.input_history_file = input_history_file
|
self.input_history_file = input_history_file
|
||||||
|
self.llm_history_file = llm_history_file
|
||||||
if chat_history_file is not None:
|
if chat_history_file is not None:
|
||||||
self.chat_history_file = Path(chat_history_file)
|
self.chat_history_file = Path(chat_history_file)
|
||||||
else:
|
else:
|
||||||
|
@ -206,10 +208,11 @@ class InputOutput:
|
||||||
else:
|
else:
|
||||||
style = None
|
style = None
|
||||||
|
|
||||||
|
completer_instance = AutoCompleter(
|
||||||
|
root, rel_fnames, addable_rel_fnames, commands, self.encoding
|
||||||
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
completer_instance = AutoCompleter(
|
|
||||||
root, rel_fnames, addable_rel_fnames, commands, self.encoding
|
|
||||||
)
|
|
||||||
if multiline_input:
|
if multiline_input:
|
||||||
show = ". "
|
show = ". "
|
||||||
|
|
||||||
|
@ -266,6 +269,14 @@ class InputOutput:
|
||||||
fh = FileHistory(self.input_history_file)
|
fh = FileHistory(self.input_history_file)
|
||||||
return fh.load_history_strings()
|
return fh.load_history_strings()
|
||||||
|
|
||||||
|
def log_llm_history(self, role, content):
|
||||||
|
if not self.llm_history_file:
|
||||||
|
return
|
||||||
|
timestamp = datetime.now().isoformat(timespec='seconds')
|
||||||
|
with open(self.llm_history_file, 'a', encoding=self.encoding) as log_file:
|
||||||
|
log_file.write(f"{role.upper()} {timestamp}\n")
|
||||||
|
log_file.write(content + "\n")
|
||||||
|
|
||||||
def user_input(self, inp, log_only=True):
|
def user_input(self, inp, log_only=True):
|
||||||
if not log_only:
|
if not log_only:
|
||||||
style = dict(style=self.user_input_color) if self.user_input_color else dict()
|
style = dict(style=self.user_input_color) if self.user_input_color else dict()
|
||||||
|
|
|
@ -258,6 +258,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
tool_error_color=args.tool_error_color,
|
tool_error_color=args.tool_error_color,
|
||||||
dry_run=args.dry_run,
|
dry_run=args.dry_run,
|
||||||
encoding=args.encoding,
|
encoding=args.encoding,
|
||||||
|
llm_history_file=args.llm_history_file,
|
||||||
)
|
)
|
||||||
|
|
||||||
fnames = [str(Path(fn).resolve()) for fn in args.files]
|
fnames = [str(Path(fn).resolve()) for fn in args.files]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue