Skip to content

Commit

Permalink
feat:add status emojis to system messages
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Jan 31, 2025
1 parent 0bd43f3 commit b1410c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
9 changes: 9 additions & 0 deletions gptme/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ def format_msgs(
if highlight:
color = ROLE_COLOR[msg.role]
userprefix = f"[bold {color}]{userprefix}[/bold {color}]"
if msg.role == "system":
first_line = msg.content.split("\n", 1)[0].lower()
isSuccess = first_line.startswith(("saved", "appended", "patch successfully", "ran"))
isError = first_line.startswith(("error", "failed"))
if isSuccess:
userprefix = f"{userprefix} ✅"
elif isError:
userprefix = f"{userprefix} ❌"

# get terminal width
max_len = shutil.get_terminal_size().columns - len(userprefix)
output = ""
Expand Down
2 changes: 1 addition & 1 deletion gptme/tools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def execute_patch(
code = kwargs.get("patch", code)

if not code:
yield Message("system", "No patch provided by the assistant")
yield Message("system", "Error: No patch provided by the assistant")
return

yield from execute_with_confirmation(
Expand Down
12 changes: 7 additions & 5 deletions gptme/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,15 @@ def execute_shell_impl(

stdout = _shorten_stdout(stdout.strip(), pre_tokens=2000, post_tokens=8000)
stderr = _shorten_stdout(stderr.strip(), pre_tokens=2000, post_tokens=2000)

msg = (
_format_block_smart(
f"Ran {'allowlisted ' if allowlisted else ''}command", cmd, lang="bash"
)
+ "\n\n"
_format_block_smart(
f"{'Failed to run' if returncode else 'Ran'} "
f"{'allowlisted ' if allowlisted else ''}command",
cmd,
lang="bash"
)
+ "\n\n"
)
if stdout:
msg += _format_block_smart("", stdout, "stdout") + "\n\n"
if stderr:
Expand Down
4 changes: 2 additions & 2 deletions gptme/tools/tmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def execute_tmux(
continue

if len(parts) < 2:
yield Message("system", f"Missing arguments for command: {command}")
yield Message("system", f"Error: Missing arguments for command: {command}")
continue

_args = parts[1]
Expand All @@ -237,7 +237,7 @@ def execute_tmux(
elif command == "kill_session":
yield kill_session(_args)
else:
yield Message("system", f"Unknown command: {command}")
yield Message("system", f"Error: Unknown command: {command}")


instructions = """
Expand Down

0 comments on commit b1410c1

Please sign in to comment.