--save now stores -p as default parameters, closes #58

This commit is contained in:
Simon Willison 2023-06-23 07:51:50 -07:00
parent 059bc1a5fe
commit 9f1085eece
3 changed files with 13 additions and 3 deletions

View file

@ -21,6 +21,11 @@ You can set the default model for a template using `--model`:
```bash
llm --system 'Summarize this' --model gpt-4 --save summarize
```
You can also save default parameters:
```bash
llm --system 'Summarize this text in the voice of $voice' \
--model gpt-4 -p voice GlaDOS --save summarize
```
## Using a template
@ -147,7 +152,7 @@ I got this:
You can also specify default values for parameters, using a `defaults:` key.
```yaml
prompt: Summarize this text in the voice of $voice
system: Summarize this text in the voice of $voice
defaults:
voice: GlaDOS
```

View file

@ -124,7 +124,6 @@ def prompt(
("--template", template),
("--continue", _continue),
("--chat", chat_id),
("--param", param),
):
if var:
bad_options.append(option)
@ -140,6 +139,8 @@ def prompt(
to_save["prompt"] = prompt
if system:
to_save["system"] = system
if param:
to_save["defaults"] = dict(param)
path.write_text(
yaml.dump(
to_save,

View file

@ -83,7 +83,11 @@ def test_templates_list(templates_path):
(["-t", "template"], None, "--save cannot be used with --template"),
(["--continue"], None, "--save cannot be used with --continue"),
(["--chat", "123"], None, "--save cannot be used with --chat"),
(["-p", "key", "value"], None, "--save cannot be used with --param"),
(
["Say hello as $name", "-p", "name", "default-name"],
{"prompt": "Say hello as $name", "defaults": {"name": "default-name"}},
None,
),
),
)
def test_templates_prompt_save(templates_path, args, expected_prompt, expected_error):