mirror of
https://github.com/TheR1D/shell_gpt.git
synced 2026-06-02 06:14:32 +02:00
REPL multiline documentation and improvements (#401)
This commit is contained in:
@@ -264,6 +264,17 @@ import requests
|
||||
response = requests.get('https://localhost:443')
|
||||
print(response.text)
|
||||
```
|
||||
To provide multiline prompt use triple quotes `"""`:
|
||||
```text
|
||||
sgpt --repl temp
|
||||
Entering REPL mode, press Ctrl+C to exit.
|
||||
>>> """
|
||||
... Explain following code:
|
||||
... import random
|
||||
... print(random.randint(1, 10))
|
||||
... """
|
||||
It is a Python script that uses the random module to generate and print a random integer.
|
||||
```
|
||||
It is also possible to pickup conversations from chat sessions (which were created using `--chat` option) and continue them in REPL mode.
|
||||
|
||||
### Roles
|
||||
|
||||
@@ -14,13 +14,11 @@ class ReplHandler(ChatHandler):
|
||||
def __init__(self, chat_id: str, role: SystemRole) -> None:
|
||||
super().__init__(chat_id, role)
|
||||
|
||||
def get_multiline_input(self) -> str:
|
||||
@classmethod
|
||||
def _get_multiline_input(cls) -> str:
|
||||
multiline_input = ""
|
||||
while True:
|
||||
user_input = typer.prompt("...", prompt_suffix="")
|
||||
while (user_input := typer.prompt("...", prompt_suffix="")) != '"""':
|
||||
multiline_input += user_input + "\n"
|
||||
if user_input == '"""':
|
||||
break
|
||||
return multiline_input
|
||||
|
||||
def handle(self, prompt: str, **kwargs: Any) -> None: # type: ignore
|
||||
@@ -44,7 +42,7 @@ class ReplHandler(ChatHandler):
|
||||
# Infinite loop until user exits with Ctrl+C.
|
||||
prompt = typer.prompt(">>>", prompt_suffix=" ")
|
||||
if prompt == '"""':
|
||||
prompt = self.get_multiline_input()
|
||||
prompt = self._get_multiline_input()
|
||||
if prompt == "exit()":
|
||||
# This is also useful during tests.
|
||||
raise typer.Exit()
|
||||
|
||||
Reference in New Issue
Block a user