mirror of
https://github.com/Hopiu/llm.git
synced 2026-05-02 10:54:46 +00:00
Add '!edit' command to modify prompts in chat sessions using default editor (#969)
* Add '!edit' command to modify prompts in chat sessions
This commit is contained in:
parent
16770611ca
commit
7dcfa31143
5 changed files with 27 additions and 0 deletions
|
|
@ -419,6 +419,7 @@ This starts a chat session:
|
|||
```
|
||||
Type 'exit' or 'quit' to exit
|
||||
Type '!multi' to enter multiple lines, then '!end' to finish
|
||||
Type '!edit' to open your default editor and modify the prompt.
|
||||
> Who are you?
|
||||
Hello! I'm just an AI, here to assist you with any questions you may have.
|
||||
My name is LLaMA, and I'm a large language model trained to provide helpful
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ llm chat -m gpt-4o
|
|||
Chatting with gpt-4o
|
||||
Type 'exit' or 'quit' to exit
|
||||
Type '!multi' to enter multiple lines, then '!end' to finish
|
||||
Type '!edit' to open your default editor and modify the prompt.
|
||||
> Tell me a joke about a pelican
|
||||
Why don't pelicans like to tip waiters?
|
||||
|
||||
|
|
|
|||
|
|
@ -330,6 +330,7 @@ llm chat -t cheesecake
|
|||
Chatting with gpt-4
|
||||
Type 'exit' or 'quit' to exit
|
||||
Type '!multi' to enter multiple lines, then '!end' to finish
|
||||
Type '!edit' to open your default editor and modify the prompt
|
||||
> who are you?
|
||||
I am a sentient cheesecake, meaning I am an artificial
|
||||
intelligence embodied in a dessert form, specifically a
|
||||
|
|
@ -350,6 +351,7 @@ If your pasted text might itself contain a `!end` line, you can set a custom del
|
|||
Chatting with gpt-4
|
||||
Type 'exit' or 'quit' to exit
|
||||
Type '!multi' to enter multiple lines, then '!end' to finish
|
||||
Type '!edit' to open your default editor and modify the prompt.
|
||||
> !multi custom-end
|
||||
Explain this error:
|
||||
|
||||
|
|
@ -362,6 +364,16 @@ urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided,
|
|||
!end custom-end
|
||||
```
|
||||
|
||||
You can also use `!edit` to open your default editor and modify the prompt before sending it to the model.
|
||||
|
||||
```
|
||||
Chatting with gpt-4
|
||||
Type 'exit' or 'quit' to exit
|
||||
Type '!multi' to enter multiple lines, then '!end' to finish
|
||||
Type '!edit' to open your default editor and modify the prompt.
|
||||
> !edit
|
||||
```
|
||||
|
||||
## Listing available models
|
||||
|
||||
The `llm models` command lists every model that can be used with LLM, along with their aliases. This includes models that have been installed using {ref}`plugins <plugins>`.
|
||||
|
|
|
|||
10
llm/cli.py
10
llm/cli.py
|
|
@ -905,6 +905,7 @@ def chat(
|
|||
click.echo("Chatting with {}".format(model.model_id))
|
||||
click.echo("Type 'exit' or 'quit' to exit")
|
||||
click.echo("Type '!multi' to enter multiple lines, then '!end' to finish")
|
||||
click.echo("Type '!edit' to open your default editor and modify the prompt")
|
||||
in_multi = False
|
||||
accumulated = []
|
||||
end_token = "!end"
|
||||
|
|
@ -916,6 +917,15 @@ def chat(
|
|||
if len(bits) > 1:
|
||||
end_token = "!end {}".format(" ".join(bits[1:]))
|
||||
continue
|
||||
if prompt.strip() == "!edit":
|
||||
edited_prompt = click.edit()
|
||||
if edited_prompt is None:
|
||||
click.echo("Editor closed without saving.", err=True)
|
||||
continue
|
||||
prompt = edited_prompt.strip()
|
||||
if not prompt:
|
||||
continue
|
||||
click.echo(prompt)
|
||||
if in_multi:
|
||||
if prompt.strip() == end_token:
|
||||
prompt = "\n".join(accumulated)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ def test_chat_basic(mock_model, logs_db):
|
|||
"Chatting with mock"
|
||||
"\nType 'exit' or 'quit' to exit"
|
||||
"\nType '!multi' to enter multiple lines, then '!end' to finish"
|
||||
"\nType '!edit' to open your default editor and modify the prompt"
|
||||
"\n> Hi"
|
||||
"\none world"
|
||||
"\n> Hi two"
|
||||
|
|
@ -86,6 +87,7 @@ def test_chat_basic(mock_model, logs_db):
|
|||
"Chatting with mock"
|
||||
"\nType 'exit' or 'quit' to exit"
|
||||
"\nType '!multi' to enter multiple lines, then '!end' to finish"
|
||||
"\nType '!edit' to open your default editor and modify the prompt"
|
||||
"\n> Continue"
|
||||
"\ncontinued"
|
||||
"\n> quit"
|
||||
|
|
@ -134,6 +136,7 @@ def test_chat_system(mock_model, logs_db):
|
|||
"Chatting with mock"
|
||||
"\nType 'exit' or 'quit' to exit"
|
||||
"\nType '!multi' to enter multiple lines, then '!end' to finish"
|
||||
"\nType '!edit' to open your default editor and modify the prompt"
|
||||
"\n> Hi"
|
||||
"\nI am mean"
|
||||
"\n> quit"
|
||||
|
|
|
|||
Loading…
Reference in a new issue