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_",
|
||||
)
|
||||
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(
|
||||
"files",
|
||||
metavar="FILE",
|
||||
nargs="*",
|
||||
help="files to edit with an LLM (optional)",
|
||||
help="files to edit with an LLM (optional)"
|
||||
)
|
||||
group.add_argument(
|
||||
"--openai-api-key",
|
||||
|
|
|
@ -784,10 +784,7 @@ class Coder:
|
|||
|
||||
messages = self.format_messages()
|
||||
|
||||
timestamp = datetime.datetime.now().isoformat(timespec='seconds')
|
||||
with open('.aider.llm.history', 'a') as log_file:
|
||||
log_file.write(f"TO LLM {timestamp}\n")
|
||||
log_file.write(format_messages(messages) + "\n")
|
||||
self.io.log_llm_history("TO LLM", format_messages(messages))
|
||||
|
||||
if self.verbose:
|
||||
utils.show_messages(messages, functions=self.functions)
|
||||
|
@ -808,6 +805,9 @@ class Coder:
|
|||
exhausted = True
|
||||
else:
|
||||
raise err
|
||||
except Exception as err:
|
||||
self.io.tool_error(f"Unexpected error: {err}")
|
||||
return
|
||||
|
||||
if exhausted:
|
||||
self.num_exhausted_context_windows += 1
|
||||
|
@ -831,10 +831,7 @@ class Coder:
|
|||
|
||||
self.io.tool_output()
|
||||
|
||||
timestamp = datetime.datetime.now().isoformat(timespec='seconds')
|
||||
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")
|
||||
self.io.log_llm_history("LLM RESPONSE", format_content("ASSISTANT", content))
|
||||
|
||||
if interrupted:
|
||||
content += "\n^C KeyboardInterrupt"
|
||||
|
|
17
aider/io.py
17
aider/io.py
|
@ -106,6 +106,7 @@ class InputOutput:
|
|||
tool_error_color="red",
|
||||
encoding="utf-8",
|
||||
dry_run=False,
|
||||
llm_history_file=None,
|
||||
):
|
||||
no_color = os.environ.get("NO_COLOR")
|
||||
if no_color is not None and no_color != "":
|
||||
|
@ -125,6 +126,7 @@ class InputOutput:
|
|||
self.yes = yes
|
||||
|
||||
self.input_history_file = input_history_file
|
||||
self.llm_history_file = llm_history_file
|
||||
if chat_history_file is not None:
|
||||
self.chat_history_file = Path(chat_history_file)
|
||||
else:
|
||||
|
@ -206,10 +208,11 @@ class InputOutput:
|
|||
else:
|
||||
style = None
|
||||
|
||||
completer_instance = AutoCompleter(
|
||||
root, rel_fnames, addable_rel_fnames, commands, self.encoding
|
||||
)
|
||||
|
||||
while True:
|
||||
completer_instance = AutoCompleter(
|
||||
root, rel_fnames, addable_rel_fnames, commands, self.encoding
|
||||
)
|
||||
if multiline_input:
|
||||
show = ". "
|
||||
|
||||
|
@ -266,6 +269,14 @@ class InputOutput:
|
|||
fh = FileHistory(self.input_history_file)
|
||||
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):
|
||||
if not log_only:
|
||||
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,
|
||||
dry_run=args.dry_run,
|
||||
encoding=args.encoding,
|
||||
llm_history_file=args.llm_history_file,
|
||||
)
|
||||
|
||||
fnames = [str(Path(fn).resolve()) for fn in args.files]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue