gpt4 book ai didi

flask - 用 flask 运行 RASA

转载 作者:行者123 更新时间:2023-12-02 03:14:30 25 4
gpt4 key购买 nike

我想在 python 代码而不是命令行中使用 --enable-api 运行 RASA。下面是我的代码,它不起作用。让我知道我该怎么做。问题是一旦我点击服务,因为 channel 是“cmdline”,它进入命令行。我不知道如何解决这个问题。

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging
import rasa_core
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.utils import EndpointConfig
from rasa_core.run import serve_application
from rasa_core import config

from rasa_core.policies.fallback import FallbackPolicy
from rasa_core.policies.keras_policy import KerasPolicy

from flask import Flask
from flask_cors import CORS, cross_origin


app = Flask(__name__)
CORS(app)

logger = logging.getLogger(__name__)

@app.route("/conversations/default/respond",methods=['POST'])
def run_weather_bot(serve_forever=True):
logging.basicConfig(level="ERROR")
interpreter = RasaNLUInterpreter('C:\\xxxx_nlu\\models\\nlu\\default\\weathernlu')
action_endpoint = EndpointConfig(url="http://xxx.xx.xx.xxx:5055/webhook")
agent = Agent.load('C:\\xxxx_nlu\\models\\dialogue', interpreter=interpreter, action_endpoint=action_endpoint)

rasa_core.run.serve_application(agent,channel='cmdline')

return agent


if __name__ == '__main__':

app.run("xxx.xx.xx.xxx",5005,debug=True)

最佳答案

您使用以下命令在 run_weather_bot 函数的命令行中调用 rasa bot。

rasa_core.run.serve_application(agent,channel='cmdline')

如您所见,它用作命令行应用程序。

我对您的代码进行了一些更改,以便与 rasa 聊天机器人进行对话。可以引用AGENT文档和 Weather bot有关 RASA 代理的连接以及 RASA 代理如何处理输入消息的文章。

def rasa_agent():
interpreter = RasaNLUInterpreter("Path for NLU")
action_endpoint = EndpointConfig(url="Webhook URL")
agent = Agent.load('Path to Dialogue', interpreter=interpreter, action_endpoint=action_endpoint)
## Next line runs the rasa in commandline
# rasa_core.run.serve_application(agent,channel='cmdline')
return agent

@app.route("/conversations/default/respond",methods=['POST'])
def run_weather_bot(serve_forever=True):

agent = rasa_agent() # calling rasa agent
## Collect Query from POST request
## Send Query to Agent
## Get Response of BOT
output = {} ## Append output
return jsonify(output)

关于flask - 用 flask 运行 RASA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56579394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com