diff --git a/.gitignore b/.gitignore index 4875f381..2f8e60b2 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ dist *.cast *.png prof +tests/output diff --git a/gptme/cli.py b/gptme/cli.py index be750bfe..45072311 100644 --- a/gptme/cli.py +++ b/gptme/cli.py @@ -262,7 +262,11 @@ def loop( # If last message was from the user (such as from crash/edited log), # then skip asking for input and generate response last_msg = log[-1] if log else None - if not last_msg or (last_msg.role in ["assistant"]): + if ( + not last_msg + or (last_msg.role in ["assistant"]) + or last_msg.content == "Interrupted" + ): inquiry = prompt_user() if not inquiry: # Empty command, ask for input again diff --git a/gptme/commands.py b/gptme/commands.py index f0d317a3..10618af9 100644 --- a/gptme/commands.py +++ b/gptme/commands.py @@ -4,6 +4,7 @@ from time import sleep from typing import Generator, Literal +from .constants import CMDFIX from .logmanager import LogManager from .message import ( Message, @@ -15,7 +16,6 @@ from .tools.context import _gen_context_msg from .tools.summarize import summarize from .tools.useredit import edit_text_with_editor -from .constants import CMDFIX logger = logging.getLogger(__name__) @@ -91,9 +91,11 @@ def handle_cmd( log.undo(1, quiet=True) log.print(show_hidden="--hidden" in args) case "rename": + log.undo(1, quiet=True) # rename the conversation new_name = args[0] if args else input("New name: ") log.rename(new_name) + print(f"Renamed conversation to {new_name}") case "fork": # fork the conversation new_name = args[0] if args else input("New name: ") @@ -105,9 +107,7 @@ def handle_cmd( print(f"Summary: {summary}") case "edit": # edit previous messages - # first undo the '/edit' command itself - assert log.log[-1].content == f"{CMDFIX}edit" log.undo(1, quiet=True) # generate editable toml of all messages @@ -128,10 +128,10 @@ def handle_cmd( log.write() # now we need to redraw the log so the user isn't seeing stale messages in their buffer # log.print() - logger.info("Applied edited messages") + print("Applied edited messages, write /log to see the result") case "context": # print context msg - print(_gen_context_msg()) + yield _gen_context_msg() case "undo": # undo the '/undo' command itself log.undo(1, quiet=True) @@ -179,6 +179,7 @@ def handle_cmd( print("Unknown command") # undo the '/help' command itself log.undo(1, quiet=True) + log.write() print("Available commands:") for cmd, desc in action_descriptions.items(): diff --git a/gptme/logmanager.py b/gptme/logmanager.py index 697a492b..be32141f 100644 --- a/gptme/logmanager.py +++ b/gptme/logmanager.py @@ -135,6 +135,7 @@ def get_last_code_block(self) -> str | None: def rename(self, name: str) -> None: # rename the conversation and log file # if you want to keep the old log, use fork() + (LOGSDIR / name).mkdir(parents=True, exist_ok=True) self.logfile.rename(LOGSDIR / name / "conversation.jsonl") self.logfile = LOGSDIR / name / "conversation.jsonl" diff --git a/gptme/tools/useredit.py b/gptme/tools/useredit.py index 0d583b0a..715f0c9a 100644 --- a/gptme/tools/useredit.py +++ b/gptme/tools/useredit.py @@ -1,6 +1,7 @@ """ Tool that lets the user edit something in a temporary file using their $EDITOR. """ + import logging import os import subprocess @@ -20,7 +21,7 @@ def edit_text_with_editor(initial_text: str, ext=None) -> str: editor = os.environ.get("EDITOR", "nano") # Open the file in the user's editor. - print("Running editor:", [editor, temp_filename]) + logger.debug("Running editor:", [editor, temp_filename]) p = subprocess.run([editor, temp_filename]) # now, we wait diff --git a/tests/test-integration.sh b/tests/test-integration.sh index 14ec8894..2f42594f 100755 --- a/tests/test-integration.sh +++ b/tests/test-integration.sh @@ -3,6 +3,11 @@ set -e set -x +# set pwd to the output directory under this script +cd "$(dirname "$0")" +mkdir -p output +cd output + # set this to indicate tests are run (non-interactive) export PYTEST_CURRENT_TEST=1 @@ -10,7 +15,16 @@ export PYTEST_CURRENT_TEST=1 echo "The project mascot is a flying pig" | gptme "What is the project mascot?" # test python command -gptme ".python print('hello world')" +gptme "/python print('hello world')" # test shell command -gptme ".shell echo 'hello world'" +gptme "/shell echo 'hello world'" + +# interactive matplotlib +gptme 'plot an x^2 graph' + +# matplotlib to file +gptme 'plot up to the 3rd degree taylor expansion of sin(x), save to sin.png' + +# interactive curses +gptme 'write a snake game with curses'