Add -@ for reading system prompt from a file
`-S @...` did not have good ergonomics for completion.
This commit is contained in:
parent
61af71d0bd
commit
95a0a29055
1 changed files with 20 additions and 2 deletions
|
|
@ -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()
|
||||
|
|
@ -369,6 +380,13 @@ main = MyCLI(
|
|||
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue