Skip to content

Commit 6090443

Browse files
committed
feat: added support for multiple prompts args, that are run in sequence
1 parent a6cec3e commit 6090443

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

gptme/cli.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def handle_cmd(
148148

149149

150150
@click.command(help=docstring)
151-
@click.argument("prompt", default=None, required=False)
151+
@click.argument("prompts", default=None, required=False, nargs=-1)
152152
@click.option(
153153
"--prompt-system",
154154
default="full",
@@ -187,7 +187,7 @@ def handle_cmd(
187187
help="Show hidden system messages.",
188188
)
189189
def main(
190-
prompt: str | None,
190+
prompts: list[str],
191191
prompt_system: str,
192192
name: str,
193193
llm: LLMChoice,
@@ -214,7 +214,7 @@ def main(
214214
else:
215215
promptmsgs = [Message("system", prompt_system)]
216216

217-
logfile = get_logfile(name)
217+
logfile = get_logfile(name, interactive=not prompts and sys.stdin.isatty())
218218
print(f"Using logdir {logfile.parent}")
219219
logmanager = LogManager.load(
220220
logfile, initial_msgs=promptmsgs, show_hidden=show_hidden
@@ -232,6 +232,11 @@ def main(
232232
command_triggered = False
233233

234234
while True:
235+
prompt = None
236+
if prompts:
237+
prompt = prompts[0]
238+
prompts = prompts[1:]
239+
235240
# if non-interactive and command has been run, exit
236241
if command_triggered and not sys.stdin.isatty():
237242
logger.info("Command triggered and not in TTY, exiting")
@@ -250,8 +255,8 @@ def main(
250255
# Empty command, ask for input again
251256
print()
252257
continue
253-
# we will exit when a prompt given on command line and we're non-interactive
254-
if prompt:
258+
# we will exit when last cli-provided prompt is done (if we're non-interactive, see above)
259+
if prompt and len(prompts) == 0:
255260
command_triggered = True
256261
prompt = None
257262
logmanager.append(Message("user", inquiry), quiet=True)
@@ -367,7 +372,7 @@ def _load_readline_history() -> None:
367372
atexit.register(readline.write_history_file, HISTORY_FILE)
368373

369374

370-
def get_logfile(name: str) -> Path:
375+
def get_logfile(name: str, interactive=True) -> Path:
371376
# let user select between starting a new conversation and loading a previous one
372377
# using the library
373378
title = "New conversation or load previous? "
@@ -385,7 +390,7 @@ def get_logfile(name: str) -> Path:
385390
]
386391

387392
# don't run pick in tests/non-interactive mode
388-
if sys.stdout.isatty():
393+
if interactive:
389394
options = [
390395
NEW_CONV,
391396
] + prev_convs

0 commit comments

Comments
 (0)