rasa icon indicating copy to clipboard operation
rasa copied to clipboard

Upgrade prompt-toolkit to 3.0

Open ancalita opened this issue 1 year ago • 0 comments

Proposed changes: Upgrades prompt-toolkit and make some edits to the use of questionary which has prompt-toolkit as dependency:

  • replace sync method questionary.ask() with ask_async(), otherwise this breaks rasa shell by raising RuntimeError: This event loop is already running.
  • use concurrent.futures.ThreadPoolExecutor to execute async code in synchronous function _get_user_input(), otherwise trying to make this function async would have resulted in breaking two tests (although rasa shell worked fine):
  1. test_console_input fails with TypeError: object str can't be used in 'await' expression
  2. test_record_messages fails with OSError: [Errno 9] Bad file descriptor.

! The ThreadPoolExecutor approach still fails test_record_messages with RuntimeErrors or OSErrors, more investigation required.

Status (please check what you already did):

  • [ ] added some tests for the functionality
  • [ ] updated the documentation
  • [x] updated the changelog (please check changelog for instructions)
  • [x] reformat files using black (please check Readme for instructions)

ancalita avatar Aug 09 '22 09:08 ancalita

@losterloh This is now ready for review after a great troubleshooting round with @tmbo 🥳

ancalita avatar Aug 10 '22 18:08 ancalita

@ancalita do you mind linking the ticket you created on the prompt-toolkit repo here so that we have a reference to it if / when we need to get back to this pr in the future?

tmbo avatar Aug 11 '22 06:08 tmbo

@ancalita do you mind linking the ticket you created on the prompt-toolkit repo here so that we have a reference to it if / when we need to get back to this pr in the future?

@tmbo I've just linked to it in the PR description. I also just noticed that prompt-toolkit version is still at 3.0.3 in poetry.lock, I'll update now and push the change.

ancalita avatar Aug 11 '22 06:08 ancalita

@tmbo I just ran a sanity check with rasa interactive on a rasa init project and everything works fine up until a point 😅 I tried this conversation:

- Hi # correct prediction
- Hey! How are you? # correct action
- fANTASTIC # here i have to correct intent to `mood_great`
- Great, carry on! # correct predicted action

After the last predicted action action_listen, I get an error, with this stacktrace:

 ERROR    rasa.core.training.interactive  - An exception occurred while recording messages.
Traceback (most recent call last):
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 1504, in record_messages
    await _predict_till_next_listen(
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 978, in _predict_till_next_listen
    await _print_history(conversation_id, endpoint)
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 483, in _print_history
    print(table)
BlockingIOError: [Errno 35] write could not complete without blocking
2022-08-11 10:34:33 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished name='Task-6' coro=<SignalRouter._dispatch() done, defined at /Users/ancalita/rasa-projects/oss-0908-3.2.x/lib/python3.9/site-packages/sanic/signals.py:121> exception=BlockingIOError(35, 'write could not complete without blocking', 0)>
Traceback (most recent call last):
  File "/Users/ancalita/rasa-projects/oss-0908-3.2.x/lib/python3.9/site-packages/sanic/signals.py", line 161, in _dispatch
    retval = await maybe_coroutine
  File "/Users/ancalita/rasa-projects/oss-0908-3.2.x/lib/python3.9/site-packages/sanic/app.py", line 1581, in run_delayed_task
    await prepped
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 1596, in run_interactive_io
    await record_messages(
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 1504, in record_messages
    await _predict_till_next_listen(
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 978, in _predict_till_next_listen
    await _print_history(conversation_id, endpoint)
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/training/interactive.py", line 483, in _print_history
    print(table)
BlockingIOError: [Errno 35] write could not complete without blocking

I've tried amending print(table, flush=True), but it didn't help. I also double-checked this is not an error dating before this PR, so I tested with rasa 3.2.5 on 3.2.x branch and no errors were triggered. Any ideas? 🆘

ancalita avatar Aug 11 '22 10:08 ancalita

🚀 A preview of the docs have been deployed at the following URL: https://11426--rasahq-docs-rasa-v2.netlify.app/docs/rasa

github-actions[bot] avatar Aug 11 '22 11:08 github-actions[bot]