【问题标题】:Flask allow chunked data or use different library?Flask 允许分块数据还是使用不同的库?
【发布时间】:2019-02-05 18:33:12
【问题描述】:

您好,我正在开发一个 python rasa 聊天机器人项目,该项目使用以下代码教程:https://github.com/RasaHQ/rasa_core/issues/119 允许发布对 rasa 框架的调用。我遇到了一个问题,如果 post 调用以块的形式出现,python 将无法接受这一点。有没有办法通过 Flask 接受分块数据,或者你会推荐不同的 webhook 库吗?提前谢谢!

Python:

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__)
    CORS(custom_webhook)

    @custom_webhook.route("/webhook", 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)

【问题讨论】:

  • 蓝图与卡住的请求没有任何关系,它们是将代码组织成模块的方式。请改写你的问题following this guide advises

标签: python flask rasa-core


【解决方案1】:

在我看来,对输入通道的分块调用没有任何意义。 您发送到 Rasa Core 输入通道的有效负载应该非常小。通常它们包括

  • 发件人 ID
  • 一些授权标头
  • 给机器人的用户消息

这应该是几千字节的大小,这使得分块请求的使用效率很低。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多