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

llm chat - readline problems still present #376

Closed
kevinburke opened this issue Dec 14, 2023 · 3 comments
Closed

llm chat - readline problems still present #376

kevinburke opened this issue Dec 14, 2023 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@kevinburke
Copy link

When I open llm chat, I expect that using the left and right arrow keys will navigate the cursor but instead I get nasty ANSI codes printed to the screen.

$ llm chat
Chatting with gpt-4
Type 'exit' or 'quit' to exit
Type '!multi' to enter multiple lines, then '!end' to finish
> foo bar ^[[D^[[D^[[D^[[D^[[D

I am using the latest version of llm, commit 5cc8efe (the readline support commit), installed by checking out this commit locally, starting a virtualenv and running "python setup.py install", then running e.g. ./venv/bin/llm.

I also verified that my Python version has readline support:

$ python
Python 3.10.13 (main, Nov  7 2023, 20:58:26) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> print(readline.__doc__)
Importing this module enables command line editing using GNU readline.

Let me know what else I can do to help troubleshoot.

@kugurerdem
Copy link

kugurerdem commented Dec 17, 2023

I had the same experience. Running rlwrap llm chat resolved the issue for me when I wanted to chat through llm. This is essentially a workaround that worked for me, but the problem still remains.

It's a bit unfortunate that this great program has issues with readline. I would really like to see this problem being addressed and solved.

@simonw simonw added bug Something isn't working help wanted Extra attention is needed labels Jan 26, 2024
@simonw simonw added this to the 0.13 milestone Jan 26, 2024
@simonw
Copy link
Owner

simonw commented Jan 26, 2024

Working with ChatGPT: https://chat.openai.com/share/b5e1a34e-e365-4455-8d17-265ef80101c0 I found this magic incantation which seems to do the right thing:

    readline.parse_and_bind("\\e[D: backward-char")
    readline.parse_and_bind("\\e[C: forward-char")

Weirdly obscure!

@simonw
Copy link
Owner

simonw commented Jan 26, 2024

Demo of that fix:

readline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants