signebedi / gptty

ChatGPT wrapper in your TTY
MIT License
47 stars 7 forks source link

Using arrow keys to edit question prints escape characters #50

Closed hyp-er closed 1 year ago

hyp-er commented 1 year ago

When trying to edit my query, you can't use your arrow keys to traverse the prompt - one extremely necessary feature when working with the TTY. It gets especially annoying when you have to delete half your prompt to fix one simple spelling mistake, which can yield incorrect responses.

signebedi commented 1 year ago

Oh, sure. We can add this. Here's a few references for using the prompt_toolkit (which is, admittedly, just another dependency for us to manage... ugh).

  1. https://stackoverflow.com/questions/75807664/issues-handling-chatgpt-streaming-response-in-terminal-using-openai-api-using
  2. https://stackoverflow.com/a/56181822/13301284

So this would look something like:

from prompt_toolkit import PromptSession

...
# this is used when we run the `chat` command
async def create_chat_room(configs=get_config_data(), log_responses:bool=True, config_path=None, verbose:bool=False):
...

    session = PromptSession()
    # Continuously send and receive messages
    while True:
...
        i = await session.prompt_async(f"{CYAN}> ")
signebedi commented 1 year ago

Added @hyp-er! Thank you for your contribution!