AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

fix: use a modern prompt to avoid ^[[D char when using arrow left and…

Open gabkk opened this issue 1 year ago • 15 comments

Background

This PR aims to fix an issue with the input prompt where arrow keys would generate unwanted characters (^[[D) in the input when using arrows.

We also want to ensure that the colored output works correctly with the new input method.

prompt_toolkit also support history with up and down arrow which could be useful if we plan to have more user interaction with the agent in the futur

Changes

  1. Replaced the input() function with prompt_toolkit's PromptSession to prevent unwanted characters when using arrow keys.
  2. Adjusted all clean_input calls to use prompt_toolkit's HTML formatting instead of colorama ANSI escape codes.
  3. Added the prompt_toolkit package to the requirements.txt file.

Documentation

The changes are documented in the form of in-code comments and by updating the clean_input function to accept FormattedText from prompt_toolkit.

Test Plan

Tested the changes by running the script and interacting with the modified prompts. Verified that the arrow keys no longer produce unwanted characters and that the colored output is displayed correctly.

PR Quality Checklist

  • [x] My pull request is atomic and focuses on a single change.
  • [x] I have thoroughly tested my changes with multiple different prompts.
  • [x] I have considered potential risks and mitigations for my changes.
  • [x] I have documented my changes clearly and comprehensively.
  • [x] I have not snuck in any "extra" small tweaks changes

gabkk avatar Apr 21 '23 18:04 gabkk

There is an another PR regarding this with readline. Why this is better than that?

Check #2558

hdkiller avatar Apr 21 '23 19:04 hdkiller

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 21 '23 20:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 22 '23 03:04 github-actions[bot]

There is an another PR regarding this with readline. Why this is better than that?

Check #2558

Hi @hdkiller

realine is already a good improvement but i believe that we will have much more interaction with auto-GPT using the terminal in the futur and readline is really basic.

prompt_toolkit allows:

  • multi-line editing
  • syntax highlighting
  • input validation (which can be really neat using gtp 3.5 turbo)
  • auto-completion
  • creating complex user interfaces with colors, styles and widget like progress bars, menus, dialog box, html tags ect..
  • mouse interaction

Which i believe will make the terminal UX much better.

I kept this PR small to know if you guys are willing to use prompt_toolkit. But i can create an other PR if this one is merged to show case how we can improve the current UI.

Some cool improvement could be to have options when auto-GPT want to execute a task, for example you want to do a web search Auto Gpt prompt display 3 option (BIng / google / duckduck go), you could use the arrow to choose between those 3 choices.

I think it will push the terminal interaction to an other level

gabkk avatar Apr 22 '23 04:04 gabkk

@ntindle

Added tests, fixed the linter issue and add colors as constants to the utils file

gabkk avatar Apr 22 '23 13:04 gabkk

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 23 '23 05:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 24 '23 02:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 26 '23 20:04 github-actions[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 28, 2023 3:26am

vercel[bot] avatar Apr 27 '23 03:04 vercel[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 27 '23 03:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 27 '23 19:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 28 '23 03:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 30 '23 04:04 github-actions[bot]

This is a mass message from the AutoGPT core team. Our apologies for the ongoing delay in processing PRs. This is because we are re-architecting the AutoGPT core!

For more details (and for infor on joining our Discord), please refer to: https://github.com/Significant-Gravitas/Auto-GPT/wiki/Architecting

p-i- avatar May 05 '23 00:05 p-i-

prompt_toolkit also support history with up and down arrow which could be useful if we plan to have more user interaction with the agent in the futur

FYI: early experiments using prompt-toolkit (the idea was to easily reuse/edit previous commands again, and to have autocomplete for directories and file names inside the workspace): #4078

agpt-ui2

Boostrix avatar May 11 '23 12:05 Boostrix

I'm getting this ^[[D issue when I press left arrow key. Hope this gets fixed soon.

ariel-frischer avatar Jun 11 '23 02:06 ariel-frischer

Simplest implementation to fix issue in #4649

erik-megarad avatar Jun 11 '23 05:06 erik-megarad

Simplest implementation to fix issue in #4649

You are the man, thank you will merge this.

ariel-frischer avatar Jun 11 '23 05:06 ariel-frischer

Closing as fixed in #4649

Pwuts avatar Sep 08 '23 13:09 Pwuts