Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Multiline REPL feature #393

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix linter + change multiline marker to triple quotes
  • Loading branch information
arafatsyed committed Dec 12, 2023
commit 3756a47131c314f2cc693dbff314791d8f2b3666
9 changes: 3 additions & 6 deletions sgpt/handlers/repl_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ def __init__(self, chat_id: str, role: SystemRole) -> None:
super().__init__(chat_id, role)

def get_multiline_input(self) -> str:
info_message = "Entering REPL multiline mode, press '}' to confirm and end multiline prompt."
typer.secho(info_message, fg="yellow")

multiline_input = ""
while True:
user_input = typer.prompt("", prompt_suffix=" ")
user_input = typer.prompt("...", prompt_suffix="")
multiline_input += user_input + "\n"
if user_input == "}":
if user_input == '"""':
break
return multiline_input

Expand All @@ -46,7 +43,7 @@ def handle(self, prompt: str, **kwargs: Any) -> None: # type: ignore
while True:
# Infinite loop until user exits with Ctrl+C.
prompt = typer.prompt(">>>", prompt_suffix=" ")
if prompt == "{":
if prompt == '"""':
prompt = self.get_multiline_input()
if prompt == "exit()":
# This is also useful during tests.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,21 @@ def test_repl_multiline(
"--repl": "temp",
}
inputs = [
"{",
'"""',
"Please remember my favorite number: 6",
"What is my favorite number + 2?",
"}",
'"""',
"exit()",
]
result = runner.invoke(
app, self.get_arguments(**dict_arguments), input="\n".join(inputs)
)

assert result.exit_code == 0
assert "{" in result.stdout
assert '"""' in result.stdout
assert "Please remember my favorite number: 6" in result.stdout
assert "What is my favorite number + 2?" in result.stdout
assert "}" in result.stdout
assert '"""' in result.stdout
assert "8" in result.stdout

def test_repl_shell(self):
Expand Down