1

我正在使用 rasa(最新版本),但由于 handle_channel 方法而无法向聊天机器人发送响应,现在我收到以下错误

"error": "Object of type coroutine is not JSON serializable"

这是我的代码,我错在哪里?

@app.route('/api/v1/<sender_id>/respond', methods=['GET', 'POST'])
    def respond(self, request, sender_id):
        request.setHeader('Content-Type', 'application/json')
        request.setHeader('Access-Control-Allow-Origin', '*')
        request_params = request_parameters(request)
        if 'query' in request_params:
            message = request_params.pop('query')
        elif 'q' in request_params:
            message = request_params.pop('q')
        else:
            request.setResponseCode(400)
            return json.dumps({"error": "Invalid parse parameter specified"})
        try:                
            out = CollectingOutputChannel()               

            response = self.agent.handle_message(message, output_channel=out, sender_id=sender_id)


            request.setResponseCode(200)
            return json.dumps(response)
        except Exception as e:                      
            request.setResponseCode(500)               
            logger.error("Caught an exception during "
                         "parse: {}".format(e), exc_info=1)
            return json.dumps({"error": "{}".format(e)})
4

1 回答 1

1

你确定你没有在这里混合方法吗?根据文档,您可能想尝试:

handle_message(message, message_preprocessor=None, **kwargs)

或者

handle_text(text_message, message_preprocessor=None, output_channel=None, sender_id='default')

请记住导入正确的库,因为自 1.0 以来进行了重命名,以防万一。

于 2019-07-25T18:05:00.607 回答