kardolus / chatgpt-cli

ChatGPT CLI is an advanced command-line interface for ChatGPT models via OpenAI and Azure, offering streaming, query mode, and history tracking for seamless, context-aware conversations. Ideal for both users and developers, it provides advanced configuration and easy setup options to ensure a tailored conversational experience with the GPT model.
MIT License
404 stars 28 forks source link

Escape chars #14

Closed p4-k4 closed 8 months ago

p4-k4 commented 9 months ago

Is there a preferred way to provide escape characters especially in cases where we want to provide multi-line code snippets with the prompt?

Cheers and thanks!

kardolus commented 9 months ago

Hi! The preferred way right now would be to use a pipe. For example, if I have multiple lines stored in my paste buffer I could do:

echo $(pbpaste) | chatgpt what can you tell me about this error?

Or you could cat a multiline file:

cat filename.txt | chatgpt give me the tldr of this file

From a UX perspective, is there a specific feature you have in mind for supporting multiline input? I was thinking perhaps there could be a multiline command flag (which would wait for 'EOF'). I feel like there could be a solution that is more user friendly possible though.

p4-k4 commented 9 months ago

Hey there,

I'm currently using your second approach but it can become quite tedious. I would prefer pasting over supplying a file too.

With single or multiline in mind, it might be nice to rather than using a pipe, perhaps we could use an append flag:

chatgpt -a "provide dart documentation comments for this piece of code"

Enter the string to append to the prompt:

main() => print('Hi mum!');

The CLI then appends the "appendable" text to the prompt on a new line before shipping the payload.

Where -a will cache the AI prompt string, then the CLI prompts/waits for us to enter a string either being single or multiline. I'm using vi mode w/ zsh so it might be nice to allow for a second chance to edit the code rather than waiting/triggering on EOF.

A small benefit of this is that we get shell session history to refer back to and can actually see code/multiline that was previously sent, in a somewhat structured/clean way. It could be useful for not only code but anything "append-able".

There's some other improvements I would like to suggest for session handling and syntax highlighting, perhaps I could put those in separate issues?

Sorry, I'm not go adept otherwise would totally contribute - this program has helped me a lot thank you.

Cheers

kardolus commented 9 months ago

Thanks! I like this idea!

I'm inclined towards implementing this. However, I'm curious about your thoughts on signaling the end of a multi-line input. Would a specific delimiter (like EOF) or a sequence (such as two consecutive Enter presses) be intuitive from a user's perspective?

p4-k4 commented 9 months ago

If it were me, I'd just allow for Enter to be pressed as normal. This would allow for further editing in the shell before we submit the "appendable" text to the prompt. Look forward to it! Thanks.

kardolus commented 9 months ago

You got it. I am thinking about perhaps allowing multiline input in the current interactive-mode (chatgpt -i). But -a could work as well.

Just in case you are not aware, in bash you can do this already:

 2023-10-07 10:13:02 ⌚  Guillermos-MacBook-Air in ~/workspace
○ → chatgpt 'what is
the capital
of the netherlands?'
The capital of the Netherlands is Amsterdam.

Will keep you posted on the progress!

kardolus commented 8 months ago

I've thoroughly investigated this issue. Without an EOF character sequence, it's challenging to define a unique termination point, especially when ignoring new-lines. I also explored the possibility of using Shift+Enter for newlines in interactive mode, but unfortunately, this key combination isn't recognized. As a result, I'm closing this issue.