Fix newline issue in llm templates list, closes #42

This commit is contained in:
Simon Willison 2023-06-17 09:51:16 +01:00
parent b55f84a7c0
commit 19e6945dde
2 changed files with 5 additions and 1 deletions

View file

@ -292,7 +292,7 @@ def templates_list():
for file in path.glob("*.yaml"):
name = file.stem
template = load_template(name)
pairs.append((name, template.prompt or ""))
pairs.append((name, (template.prompt or "").replace("\n", " ")))
max_name_len = max(len(p[0]) for p in pairs)
fmt = "{name:<" + str(max_name_len) + "} : {prompt}"
for name, prompt in sorted(pairs):

View file

@ -36,10 +36,14 @@ def test_templates_list(templates_path):
(templates_path / "three.yaml").write_text(
"template three is very long " * 4, "utf-8"
)
(templates_path / "four.yaml").write_text(
"'this one\n\nhas newlines in it'", "utf-8"
)
runner = CliRunner()
result = runner.invoke(cli, ["templates", "list"])
assert result.exit_code == 0
assert result.output == (
"four : this one has newlines in it\n"
"one : template one\n"
"three : template three is very long template three is very long template thre...\n"
"two : template two\n"