Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support piping stdin into gptme -r (resume) #344

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gptme/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def confirm_func(msg) -> bool:
if prompt_msgs:
while prompt_msgs:
msg = prompt_msgs.pop(0)
if not msg.content.startswith("/"):
if not msg.content.startswith("/") and msg.role == "user":
msg = _include_paths(msg, workspace)
manager.append(msg)
# if prompt is a user-command, execute it
if execute_cmd(msg, manager, confirm_func):
if msg.role == "user" and execute_cmd(msg, manager, confirm_func):
continue

# Generate and execute response for this prompt
Expand Down
11 changes: 7 additions & 4 deletions gptme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,11 @@ def main(

# if stdin is not a tty, we might be getting piped input, which we should include in the prompt
was_piped = False
piped_input = None
if not sys.stdin.isatty():
# fetch prompt from stdin
prompt_stdin = _read_stdin()
if prompt_stdin:
# TODO: also append if existing convo loaded/resumed
initial_msgs += [Message("system", f"```stdin\n{prompt_stdin}\n```")]
piped_input = _read_stdin()
if piped_input:
was_piped = True

# Attempt to switch to interactive mode
Expand Down Expand Up @@ -237,6 +236,8 @@ def main(

if resume:
logdir = get_logdir_resume()
if piped_input:
prompt_msgs.append(Message("system", f"```stdin\n{piped_input}\n```"))
# don't run pick in tests/non-interactive mode, or if the user specifies a name
elif (
interactive
Expand All @@ -248,6 +249,8 @@ def main(
logdir = pick_log()
else:
logdir = get_logdir(name)
if piped_input:
initial_msgs.append(Message("system", f"```stdin\n{piped_input}\n```"))

if workspace == "@log":
workspace_path: Path | None = logdir / "workspace"
Expand Down
Loading