tbckr / sgpt

SGPT is a command-line tool that provides a convenient way to interact with OpenAI models, enabling users to run queries, generate shell commands and produce code directly from the terminal.
MIT License
210 stars 23 forks source link

Provide input via stdin and as an argument #128

Closed tbckr closed 4 months ago

tbckr commented 10 months ago

Is your feature request related to a problem? Please describe.

Sometimes I want to pipe in some data (e.g. a file) and provide a prompt, what to do with the provided input via stdin.

Describe the solution you'd like

I want to be able to provide input via stdin and as an argument.

The input via an argument should be appended in such cases.

Example: cat some-file | sgpt "my prompt what i want to do with this file"

Describe alternatives you've considered

You can concatinate input in bash by using parentheses (see example below), but this solution is rather complicated.

( cat some-file; echo "my prompt what i want to do with this file"; ) | sgpt

Search

Code of Conduct

Additional context

No response

tbckr commented 9 months ago

won't be implemented for now

CGamesPlay commented 4 months ago

What was the motivation for not merging this feature? I was experimenting with sgpt recently and this was one of the first things I wanted to do. Specifically:

$ git diff --cached | sgpt "Summarize all of these changes in a single line."

I would have liked sgpt to send two messages to the chat, one with the piped file, and the second with the command-line prompt.

tbckr commented 4 months ago

Good question. At that time, this would have meant that I had to introduce another breaking change which meant a new major release - which I was not willing to do. The software was supposed to be more stable. In fact, right now, the first param is interpreted as a modifier and not as a prompt. This is a breaking change in the cli command. Suggestion: Would it be feasible for you, if you could an additional prompt as the second argument, when data is piped? Then you would have to add an modifier to be able to add an additional prompt. At the same time, I do not really like this, because it is different from the default behaviour, when no data is piped. Moreover, one would still have to decide where to add the prompt in the message - in front of or behind the piped data. The last option would be to introduce this breaking change and create a major release. How bad do you want this feature? Does the current workaround not work for you?

CGamesPlay commented 4 months ago

Yes, it's fine to have a second argument for me (so like pbpaste | sgpt SUBCOMMAND "Summarize this in a single line"). If I'm designing the interface from scratch, what I'd probably do is use a flag as a placeholder to indicate where piped input goes (so like pbpaste | sgpt "Summarize this in a single line" --stdin). Again, ideally these then get delivered as two separate messages to the model rather than catenated into a single message, but that's more minor.

The current workaround doesn't work for me; it's not ergonomic. My "current workaround" is to use llm instead when I want to do this (pbpaste | llm "Summarize this as a single line"), but I want to use sgpt because it's much easier to install a single binary than an entire python package.

tbckr commented 4 months ago

Thank you very much for your input!

I will reopen this issue and integrate it. I cannot give you a timeline right now, but I will try to do it in a timely manner.