【问题标题】:how to get response from qna maker in rasa chatbot?如何在 rasa 聊天机器人中获得 qna 制造商的回复?
【发布时间】:2020-03-09 18:41:24
【问题描述】:

按照https://rasa.com/docs/rasa/migrate-from/microsoft-luis-to-rasa/ 中的说明,我将我的 luis 迁移到了 rasa。 我有一个 python 代码,它从 QnA Maker 知识库中获取答案并以 json 格式给出结果。 现在我的工作是 rasa 必须获取 python 代码的结果并将该结果作为聊天机器人的响应。 我怎样才能做到这一点? 我应该在哪里部署这个 python 代码? 下面是我的python代码。

v1 = '锗在哪里'

def 会议室():

import http.client, urllib.parse, json, time, sys

host = "newbot.azurewebsites.net"

endpoint_key = "xxxxxxxx-8xxe-xxxx-9xx2-7cxx4fxxxxx"

route = "/qnamaker/knowledgebases/xxxx052f-4xxa-xx7d-xxxx-4xxadxxxxxx/generateAnswer"

q1 = {'question':v1}
question = str(q1)

headers = {
           'Authorization': 'EndpointKey ' + endpoint_key,
           'Content-Type': 'application/json'
           }
try:
    conn = http.client.HTTPSConnection(host,port=443)
    conn.request ("POST", route,  question, headers)
    response = conn.getresponse ()
    answer = response.read ()
    print(json.dumps(json.loads(answer), indent=4))
except :
    print ("Unexpected error:", sys.exc_info()[0])
    print ("Unexpected error:", sys.exc_info()[1])

会议室()

【问题讨论】:

    标签: qnamaker rasa


    【解决方案1】:

    您可以将其实现为 https://rasa.com/docs/rasa/core/actions/#custom-actions 。使用 rasa-sdk,您需要定义一个执行 dispatcher.utter_message(<your formatted output here>) 的操作作为其 run 方法的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多