Skip to content

Commit

Permalink
fix: shorten interrupt message content
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmi committed Jan 5, 2025
1 parent 8be2b4f commit 420b2d9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
10 changes: 3 additions & 7 deletions gptme/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path

from .commands import action_descriptions, execute_cmd
from .constants import PROMPT_USER
from .constants import INTERRUPT_CONTENT, PROMPT_USER
from .init import init
from .llm import reply
from .llm.models import get_model
Expand Down Expand Up @@ -136,11 +136,7 @@ def confirm_func(msg) -> bool:
)
except KeyboardInterrupt:
console.log("Interrupted. Stopping current execution.")
manager.append(
Message(
"system", "User hit Ctrl-c to interrupt the process"
)
)
manager.append(Message("system", INTERRUPT_CONTENT))
break
finally:
clear_interruptible()
Expand Down Expand Up @@ -209,7 +205,7 @@ def step(
if (
not last_msg
or (last_msg.role in ["assistant"])
or last_msg.content == "Interrupted"
or last_msg.content == INTERRUPT_CONTENT
or last_msg.pinned
or not any(role == "user" for role in [m.role for m in log])
): # pragma: no cover
Expand Down
4 changes: 3 additions & 1 deletion gptme/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from time import sleep
from typing import Literal

from .constants import INTERRUPT_CONTENT

from . import llm
from .logmanager import LogManager, prepare_messages
from .message import (
Expand Down Expand Up @@ -183,7 +185,7 @@ def edit(manager: LogManager) -> Generator[Message, None, None]: # pragma: no c
try:
sleep(1)
except KeyboardInterrupt:
yield Message("system", "User hit Ctrl-c to interrupt the process")
yield Message("system", INTERRUPT_CONTENT)
return
manager.edit(list(reversed(res)))
print("Applied edited messages, write /log to see the result")
Expand Down
3 changes: 3 additions & 0 deletions gptme/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
PROMPT_ASSISTANT = (
f"[bold {ROLE_COLOR['assistant']}]Assistant[/bold {ROLE_COLOR['assistant']}]"
)


INTERRUPT_CONTENT = "Interrupted by user"
4 changes: 3 additions & 1 deletion gptme/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from collections.abc import Generator
from functools import lru_cache

from gptme.constants import INTERRUPT_CONTENT

from ..util.interrupt import clear_interruptible

from ..message import Message
Expand Down Expand Up @@ -129,7 +131,7 @@ def execute_msg(msg: Message, confirm: ConfirmFunc) -> Generator[Message, None,
clear_interruptible()
yield Message(
"system",
"User hit Ctrl-c to interrupt the process",
INTERRUPT_CONTENT,
call_id=tooluse.call_id,
)
break
Expand Down

0 comments on commit 420b2d9

Please sign in to comment.