rasa: asyncio - исключение задачи никогда не получалось, пока выполняются действия - PullRequest
0 голосов
/ 02 декабря 2019

контекст

Я создаю чат-бота, используя https://rasa.com

  1. rasa data validate не генерирует ошибок
  2. rasa train не генерирует ошибок
  3. rasa run actions -vv запускает действия
  4. rasa shell -vv запускает помощника

ошибка

  • возникает в shell, когда язапустить намерение, включающее аутентификацию
    • asyncio - Task exception was never retrieved future: <Task finished coro=<configure_app.<locals>.run_cmdline_io() done, defined at c:\app\miniconda2\envs\my_ens\lib\site-packages\rasa\core\run.py:124> exception=TimeoutError()>
    • asyncio - Task exception was never retrieved future: <Task finished coro=<RestInput.on_message_wrapper() done, defined at c:\app\miniconda2\envs\my_envs\lib\site-packages\rasa\core\channels\channel.py:392> exception=AttributeError("'dict' object has no attribute 'split'") created at c:\app\miniconda2\envs\my_envs\lib\site-packages\rasa\core\channels\channel.py:432>
    • AttributeError: 'dict' object has no attribute 'split'
  • Действие работает отлично иполучает api_token от REST API

Вопрос

Почему я получаю эти ошибки, когда действие получает токен аутентификации и отправляет его обратно в Rasa?

файл: actions.py

from rasa_core_sdk.forms import FormAction
from rasa_core_sdk import Action, Tracker
from rasa_core_sdk.events import SlotSet
from rasa_core_sdk.executor import CollectingDispatcher
from typing import Any, Text, Dict, List, Union
import inspect
import json
import logging
import os
import sys
sys.path.append(os.path.join(os.getcwd(), "a_submodule"))
from dunningcashflow import Transactions, Authentication


class ActionUserLogin(Action):

    def name(self) -> Text:

        logging.debug(
            "%s %s - %s",
            "="*10,
            "ActionUserLogin",
            inspect.currentframe().f_code.co_name
        )
        return "action_user_login"

    def run(
        self,
        dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]
    ) -> List[Dict[Text, Any]]:

        authentication_back_end = tracker.get_slot(
            "authentication_back_end"
        )
        authentication_api_token = tracker.get_slot(
            "authentication_api_token"
        )
        authorization = GetAuthorization(
            authentication_back_end,
            authentication_api_token
        )

        logging.info("authorization : %s", authorization)

        dispatcher.utter_message(
            authorization
        )

        if authorization is None:
            # TODO: indicate that the authorization code or the URL is incorrect
            return [SlotSet("authorization", None)]
        elif hasattr(authorization, "code"):
            return [SlotSet("authorization", authorization["code"])]
        elif hasattr(authorization, "Authorization"):
            return [SlotSet("authorization", authorization["Authorization"])]
        elif hasattr(authorization, "message"):
            return [SlotSet("authorization", authorization["message"])]
        else:
            return [SlotSet("authorization", authorization)]

def GetAuhorization(authentication_back_end, authentication_api_token):
    """
    GetAuthorization retrieves the authorization code
    from the REST API
    """

    url = BACK_ENDS[authentication_back_end]['resource']

    authentication = Authentication()

    authentication.login(api_token=authentication_api_token, url=url)

    return authentication.authorization

rasa run actions -vv

2019-12-02 02:31:54.667761: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2019-12-02 02:31:58 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa_core_sdk\__init__.py:12: UserWarning: The 'rasa_core_sdk' package has been renamed. You should change your imports to use 'rasa_sdk' instead.
  UserWarning,
2019-12-02 02:31:58 DEBUG    root  - ========== ActionUserLogin - name
2019-12-02 02:31:58 INFO     rasa_sdk.executor  - Registered function for 'action_user_login'.
2019-12-02 02:31:58 DEBUG    root  - ========== FindBackEnds - name
2019-12-02 02:31:58 INFO     rasa_sdk.executor  - Registered function for 'find_back_ends'.
2019-12-02 02:31:58 DEBUG    root  - ========== ActionHelloWorld - name
2019-12-02 02:31:58 INFO     rasa_sdk.executor  - Registered function for 'action_hello_world'.
2019-12-02 02:31:58 INFO     root  - ========== AuthenticationLoginForm - name
2019-12-02 02:31:58 INFO     rasa_sdk.executor  - Registered function for 'authentication_form'.
2019-12-02 02:31:58 DEBUG    rasa_sdk.utils  - Using the default number of Sanic workers (1).
2019-12-02 02:32:50 DEBUG    rasa_sdk.executor  - Received request to run 'action_user_login'
2019-12-02 02:32:50 DEBUG    root  - ========== ActionUserLogin - run
2019-12-02 02:32:50 DEBUG    root  - ========== Authentication - login
2019-12-02 02:32:50 DEBUG    urllib3.connectionpool  - Starting new HTTPS connection (1): api.a_working_domain.com:443
2019-12-02 02:32:50 DEBUG    urllib3.connectionpool  - https://api.a_working_domain.com:443 "POST /creditor HTTP/1.1" 200 None
{"Authorization":"<auth_code>"}
2019-12-02 02:32:50 INFO     root  - authorization : {'Authorization': '<auth_code>'}
2019-12-02 02:32:50 DEBUG    rasa_sdk.executor  - Finished running 'action_user_login'

rasa shell -vv

2019-12-02 02:32:47 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 5 events
2019-12-02 02:32:47 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'entity_authentication_api_token': 1.0, 'entity_authentication_back_end': 1.0, 'intent_login_all_intents': 1.0, 'slot_endpoint_0': 1.0, 'prev_action_listen': 1.0, 'slot_authentication_back_end_0': 1.0, 'entity_endpoint': 1.0, 'slot_authentication_api_token_0': 1.0}]
2019-12-02 02:32:47 DEBUG    rasa.core.policies.memoization  - There is a memorised next action '8'
2019-12-02 02:32:48 DEBUG    rasa.core.policies.form_policy  - There is no active form
2019-12-02 02:32:48 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_MemoizationPolicy
2019-12-02 02:32:48 DEBUG    rasa.core.processor  - Predicted next action 'action_user_login' with confidence 1.00.
2019-12-02 02:32:48 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_user_login'.
2019-12-02 02:32:50 DEBUG    rasa.core.processor  - Action 'action_user_login' ended with events '['BotUttered(text: {\'Authorization\': \'`<auth_code>\'}, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})', "SlotSet(key: authorization, value: {'Authorization': '`<auth_code>'})"]'
2019-12-02 02:32:50 DEBUG    rasa.core.processor  - Current slot values:
        authentication_api_token: <api_token>
        authentication_back_end: beta
        authorization: {'Authorization': '`<auth_code>'}
        endpoint: authentication
        requested_slot: None
2019-12-02 02:32:50 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'default'.
2019-12-02 02:32:56 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished coro=<configure_app.<locals>.run_cmdline_io() done, defined at c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\run.py:124> exception=TimeoutError()>
Traceback (most recent call last):
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\run.py", line 128, in run_cmdline_io
    server_url=constants.DEFAULT_SERVER_FORMAT.format("http", port)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\console.py", line 135, in record_messages
    async for response in bot_responses:
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\console.py", line 101, in send_message_receive_stream
    async for line in resp.content:
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\streams.py", line 39, in __anext__
    rv = await self.read_func()
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\streams.py", line 328, in readline
    await self._wait('readline')
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\streams.py", line 296, in _wait
    await waiter
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\helpers.py", line 596, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError
Transport closed @ ('127.0.0.1', 64497) and exception experienced during error handling
2019-12-02 02:32:56 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished coro=<RestInput.on_message_wrapper() done, defined at c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py:392> exception=AttributeError("'dict' object has no attribute 'split'") created at c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py:432>
source_traceback: Object created at (most recent call last):
  File "c:\app\miniconda2\envs \my-envs\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\app\miniconda2\envs \my-envs\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\App\Miniconda2\envs \my-envs\Scripts\rasa.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\__main__.py", line 76, in main
    cmdline_arguments.func(cmdline_arguments)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\cli\shell.py", line 101, in shell
    rasa.cli.run.run(args)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\cli\run.py", line 114, in run
    rasa.run(**vars(args))
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\run.py", line 56, in run
    **kwargs,
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\run.py", line 206, in serve_application
    endpoints.lock_store if endpoints else None
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\app.py", line 1133, in run
    serve(**server_settings)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\server.py", line 885, in serve
    loop.run_forever()
  File "c:\app\miniconda2\envs \my-envs\lib\asyncio\base_events.py", line 534, in run_forever
    self._run_once()
  File "c:\app\miniconda2\envs \my-envs\lib\asyncio\base_events.py", line 1763, in _run_once
    handle._run()
  File "c:\app\miniconda2\envs \my-envs\lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\spf\framework.py", line 512, in _handle_request
    stream_callback)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\app.py", line 1002, in handle_request
    await stream_callback(response)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\server.py", line 498, in stream_response
    self.request.version, keep_alive, self.keep_alive_timeout
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\response.py", line 110, in stream
    await self.streaming_fn(self)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 432, in stream
    on_new_message, text, q, sender_id, input_channel, metadata
Traceback (most recent call last):
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 406, in on_message_wrapper
    await on_new_message(message)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 82, in handler
    await app.agent.handle_message(*args, **kwargs)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\agent.py", line 486, in handle_message
    return await processor.handle_message(message)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 96, in handle_message
    await self._predict_and_execute_next_action(message, tracker)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 413, in _predict_and_execute_next_action
    action, tracker, message.output_channel, self.nlg, policy, confidence
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 523, in _run_action
    await self._send_bot_messages(events, tracker, output_channel)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 445, in _send_bot_messages
    await output_channel.send_response(tracker.sender_id, e.message())
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 185, in send_response
    await self.send_text_message(recipient_id, message.pop("text"), **message)
  File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 326, in send_text_message
    for message_part in text.split("\n\n"):
AttributeError: 'dict' object has no attribute 'split'
...