Skip to content

Commit

Permalink
fix: improve smaller model response on user refusals (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmi authored Jan 4, 2025
1 parent 54253a5 commit 11708dd
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
8 changes: 6 additions & 2 deletions gptme/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion gptme/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions gptme/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion gptme/tools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion gptme/tools/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions gptme/tools/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gptme/tools/tmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion gptme/util/ask_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11708dd

Please sign in to comment.