From 11708dd113057b974f55dd3f9e9f2ec29ebbda5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Pardou?= Date: Sat, 4 Jan 2025 16:59:46 +0100 Subject: [PATCH] fix: improve smaller model response on user refusals (#374) --- gptme/chat.py | 8 ++++++-- gptme/commands.py | 2 +- gptme/prompts.py | 1 + gptme/tools/patch.py | 2 +- gptme/tools/python.py | 2 +- gptme/tools/save.py | 11 ++++++++--- gptme/tools/tmux.py | 2 +- gptme/util/ask_execute.py | 4 +++- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gptme/chat.py b/gptme/chat.py index 5f3ff408f..ac65b6c61 100644 --- a/gptme/chat.py +++ b/gptme/chat.py @@ -136,7 +136,11 @@ def confirm_func(msg) -> bool: ) except KeyboardInterrupt: console.log("Interrupted. Stopping current execution.") - manager.append(Message("system", "Interrupted")) + manager.append( + Message( + "system", "User hit Ctrl-c to interrupt the process" + ) + ) break finally: clear_interruptible() @@ -237,7 +241,7 @@ def step( yield from execute_msg(msg_response, confirm) except KeyboardInterrupt: clear_interruptible() - yield Message("system", "Interrupted") + yield Message("system", "User hit Ctrl-c to interrupt the process") finally: clear_interruptible() diff --git a/gptme/commands.py b/gptme/commands.py index e3ba2afb8..bb89e8295 100644 --- a/gptme/commands.py +++ b/gptme/commands.py @@ -183,7 +183,7 @@ def edit(manager: LogManager) -> Generator[Message, None, None]: # pragma: no c try: sleep(1) except KeyboardInterrupt: - yield Message("system", "Interrupted") + yield Message("system", "User hit Ctrl-c to interrupt the process") return manager.edit(list(reversed(res))) print("Applied edited messages, write /log to see the result") diff --git a/gptme/prompts.py b/gptme/prompts.py index c766453bd..faffe98e1 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -128,6 +128,7 @@ def prompt_gptme(interactive: bool) -> Generator[Message, None, None]: You are in interactive mode. The user is available to provide feedback. You should show the user how you can use your tools to write code, interact with the terminal, and access the internet. The user can execute the suggested commands so that you see their output. +If the user aborted or interrupted an operation don't try it again, ask for clarification instead. If clarification is needed, ask the user. """.strip() diff --git a/gptme/tools/patch.py b/gptme/tools/patch.py index 6b4f6764a..e9270ed22 100644 --- a/gptme/tools/patch.py +++ b/gptme/tools/patch.py @@ -241,7 +241,7 @@ def execute_patch( code = kwargs.get("patch", code) if not code: - yield Message("system", "No patch provided") + yield Message("system", "No patch provided by the assistant") return yield from execute_with_confirmation( diff --git a/gptme/tools/python.py b/gptme/tools/python.py index 0a829f129..479e5f01f 100644 --- a/gptme/tools/python.py +++ b/gptme/tools/python.py @@ -114,7 +114,7 @@ def execute_python( print_preview(code, "python") if not confirm("Execute this code?"): # early return - yield Message("system", "Aborted, user chose not to run command.") + yield Message("system", "Execution aborted: user chose not to run this code.") return # Create an IPython instance if it doesn't exist yet diff --git a/gptme/tools/save.py b/gptme/tools/save.py index 5e9b20baa..b72629824 100644 --- a/gptme/tools/save.py +++ b/gptme/tools/save.py @@ -97,13 +97,15 @@ def execute_save_impl( # Check if file exists if path.exists(): if not confirm("File exists, overwrite?"): - yield Message("system", "Save cancelled.") + yield Message("system", "Save aborted: user refused to overwrite the file.") return # Check if folder exists if not path.parent.exists(): if not confirm("Folder doesn't exist, create it?"): - yield Message("system", "Save cancelled.") + yield Message( + "system", "Save aborted: user refused to create a missing folder." + ) return path.parent.mkdir(parents=True) @@ -122,7 +124,10 @@ def execute_append_impl( path = path.expanduser() if not path.exists(): if not confirm(f"File {path_display} doesn't exist, create it?"): - yield Message("system", "Append cancelled.") + yield Message( + "system", + "Append aborted: user refused to create the missing destination file.", + ) return # strip leading newlines diff --git a/gptme/tools/tmux.py b/gptme/tools/tmux.py index 74a794afa..c97a9cb4b 100644 --- a/gptme/tools/tmux.py +++ b/gptme/tools/tmux.py @@ -170,7 +170,7 @@ def execute_tmux( print_preview(f"Command: {cmd}", "bash", copy=True) if not confirm(f"Execute command: {cmd}?"): - yield Message("system", "Command execution cancelled.") + yield Message("system", "Execution aborted: user chose not to run the command.") return parts = cmd.split(maxsplit=1) diff --git a/gptme/util/ask_execute.py b/gptme/util/ask_execute.py index ef53a6bf5..a00c97643 100644 --- a/gptme/util/ask_execute.py +++ b/gptme/util/ask_execute.py @@ -246,7 +246,9 @@ def execute_with_confirmation( try: # Get confirmation if not confirm_fn(confirm_msg or f"Execute on {path}?"): - yield Message("system", "Operation cancelled.") + yield Message( + "system", "Operation aborted: user chose not to run the operation." + ) return # Get potentially edited content