简体   繁体   中英

Unable to import HttpInputComponent in python from rasa_core package

Python 3.64
Rasa_core version 0.14.5

Trying to integrate bot from python with API. However, it is giving me an error for the HttpInputComponent import. Please guide with the correct lib/code. Below is my code.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging

from rasa_core.channels.channel import RestInput  
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.channels.channel import UserMessage
from rasa_core.channels import CollectingOutputChannel

from rasa_core.channels.rest import HttpInputComponent
from flask import Blueprint, request, jsonify

logger = logging.getLogger(__name__)


class SimpleWebBot(HttpInputComponent):
    """A simple web bot that listens on a url and responds."""

    def blueprint(self, on_new_message):
        custom_webhook = Blueprint('custom_webhook', __name__)

        @custom_webhook.route("/status", methods=['GET'])
        def health():
            return jsonify({"status": "ok"})

        @custom_webhook.route("/", methods=['POST'])
        def receive():
            payload = request.json
            sender_id = payload.get("sender", None)
            text = payload.get("message", None)
            out = CollectingOutputChannel()
            on_new_message(UserMessage(text, out, sender_id))
            responses = [m for _, m in out.messages]
            return jsonify(responses)

        return custom_webhook


def run(serve_forever=True):
    # path to your NLU model
    interpreter = RasaNLUInterpreter("models/nlu/default/current")
    # path to your dialogues models`enter code here`
    agent = Agent.load("models/dialogue", interpreter=interpreter)
    # http api endpoint for responses
    input_channel = SimpleWebBot()
    if serve_forever:
        agent.handle_channel(RestInput(5004, "/chat", input_channel))
    return agent

The response is as below:

C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\Scripts\python.exe C:/Big_Data_Utils/Python/projects/rasa_nlu/serve.py
C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Big_Data_Utils\Python_Proj\rasa_nlu\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
  File "C:/Big_Data_Utils/Python/projects/rasa_nlu/serve.py", line 15, in <module>
    from rasa_core.channels.rest import HttpInputComponent
ModuleNotFoundError: No module named 'rasa_core.channels.rest'

Process finished with exit code 1

Thank you.

The class name has been changed in 0.14

instead of

from rasa_core.channels.rest import HttpInputComponent

you should use:

from rasa_core.channels.rasa_chat import RestInput

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM