Skip to content

Commit

Permalink
fix: include mention of user-edited save/patch/command in system resp…
Browse files Browse the repository at this point in the history
…onse
  • Loading branch information
ErikBjare committed Dec 5, 2024
1 parent d01b943 commit 93e126a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions gptme/tools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ def execute_patch(
return

# Get potentially edited content
code = get_editable_text()
edited_code = get_editable_text()
was_edited = edited_code != code
code = edited_code

try:
with open(path) as f:
Expand All @@ -256,8 +258,10 @@ def execute_patch(
"Note: The patch was big and larger than the file. In the future, try writing smaller patches or use the save tool instead."
)
warnings_str = ("\n".join(warnings) + "\n") if warnings else ""

yield Message("system", f"{warnings_str}Patch successfully applied to {fn}")
edit_msg = " (edited by user)" if was_edited else ""
yield Message(
"system", f"{warnings_str}Patch successfully applied to {fn}{edit_msg}"
)
except (ValueError, FileNotFoundError) as e:
yield Message("system", f"Patch failed: {e.args[0]}")

Expand Down
7 changes: 5 additions & 2 deletions gptme/tools/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def execute_save(
return

# Get potentially edited content
content = get_editable_text()
edited_content = get_editable_text()
was_edited = edited_content != content
content = edited_content
finally:
clear_editable_text()

Expand All @@ -137,7 +139,8 @@ def execute_save(
print("Saving to " + fn)
with open(path, "w") as f:
f.write(content)
yield Message("system", f"Saved to {fn}")
edit_msg = " (edited by user)" if was_edited else ""
yield Message("system", f"Saved to {fn}{edit_msg}")


def execute_append(
Expand Down

0 comments on commit 93e126a

Please sign in to comment.