繁体   English   中英

无法从 rasa_core package 导入 python 中的 HttpInputComponent

[英]Unable to import HttpInputComponent in python from rasa_core package

Python 3.64
Rasa_core 版本 0.14.5

尝试将 python 中的机器人与 API 集成。 但是,它给了我一个HttpInputComponent导入错误。 请使用正确的库/代码进行指导。 下面是我的代码。

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

响应如下:

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'

进程以退出代码 1 结束

谢谢你。

class 名称已在 0.14 中更改

代替

from rasa_core.channels.rest import HttpInputComponent

你应该使用:

from rasa_core.channels.rasa_chat import RestInput

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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