Skip to content

Commit

Permalink
Add -@ for reading system prompt from a file
Browse files Browse the repository at this point in the history
`-S @...` did not have good ergonomics for completion.
  • Loading branch information
jepler committed Apr 10, 2024
1 parent 61af71d commit 95a0a29
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/chap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,23 @@ def colonstr(arg: str) -> tuple[str, str]:


def set_system_message(ctx: click.Context, param: click.Parameter, value: str) -> None:
if value and value.startswith("@"):
if value is None:
return
if value.startswith("@"):
with open(value[1:], "r", encoding="utf-8") as f:
value = f.read().rstrip()
value = f.read().strip()
ctx.obj.system_message = value


def set_system_message_from_file(
ctx: click.Context, param: click.Parameter, value: click.File
) -> None:
if value is None:
return
content = value.read().strip()
ctx.obj.system_message = content


def set_backend(ctx: click.Context, param: click.Parameter, value: str) -> None:
if value == "list":
formatter = ctx.make_formatter()
Expand Down Expand Up @@ -369,6 +380,13 @@ def format_options(
help="Show the version and exit",
callback=version_callback,
),
click.Option(
("--system-message-file", "-@"),
type=click.File("r"),
default=None,
callback=set_system_message_from_file,
expose_value=False,
),
click.Option(
("--system-message", "-S"),
type=str,
Expand Down

0 comments on commit 95a0a29

Please sign in to comment.