【发布时间】:2020-10-27 19:38:56
【问题描述】:
全部,
我已经使用 Python(版本 - 3.6.4.)使用 Rasa(版本-1.10.8)框架构建了机器人。尝试使用烧瓶在网络上部署它,但无法建立连接。
Bot 在控制台中工作得非常好。`from flask import Flask, request, render_template, Response。
- Rasa 服务器正在端口 http://localhost:5005 上运行
- 使用 'rasa run -m models --enable-api --endpoints endpoints.yml 启动服务器
- 动作服务器正在运行(命令使用 rasa 运行动作)
- 以下代码位于项目根文件夹下的run.py中。
问题 -
- 从网页接收到文本后,它没有传递给 Rasa。
- 硬编码的内容也不会被发送回网页。
import json
from flask import Flask, request, render_template, Response
app = Flask(__name__)
@app.route('/', methods = ['POST', 'GET'])
def index():
return render_template('index.html')
@app.route('/',methods = ['POST','GET'])
def index_get():
val = str(request.args.get('text'))
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
data = json.dumps({"sender": "Rasa", "message": val})
res = request.post('http://localhost:5005/webhooks/rest/webhook', data=data, headers=headers)
res = res.json()
val = res[0]['text']
return render_template('index.html', val=val)
if __name__ == '__main__':
app.run()(debug=True)`
使用简单的html页面。这存在于 templates/index.html
<html>
<head>
<title>CHATBOT</title>
</head>
<body>
<h1>CHATBOT</h1>
<form>
<label for="text">You:</label><br>
<input type="text" id="text" name="text"><br>
<p>{{val}}</p>
</form>
</body>
</html>
【问题讨论】:
-
索引文件:
CHATBOT CHATBOT
-
"从网页接收到文本后,它没有传递给 Rasa" 是否正在对 Rasa 进行 API 调用?您可以通过检查浏览器开发人员工具中的“网络”选项卡和/或使用
rasa run --debug运行您的 rasa 服务器来检查这一点 -
我需要在 rasa 文件夹下的 server.py 中做任何更改吗?
标签: python flask rasa-nlu rasa