gpt4 book ai didi

python - 无法初始化 Flask 应用程序和 rasa_nlu.server 之间的持久器

转载 作者:行者123 更新时间:2023-12-01 09:22:49 27 4
gpt4 key购买 nike

我有一个web-app chat and a Rasa server这是一个聊天机器人,我希望聊天机器人处理从第一个聊天机器人收到的消息。

在端口 8000 上启动应用程序并在端口 5000 上启动 rasa_nlu.server 后,我很难让服务器处理消息。事实上,在 app.py 终端上,获取所有路由的脚本:

 * Detected change in '/home/mike/Programing/Rasa/myflaskapp/app.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 213-078-895
{'error': "No project found with name 'default'."}
HOUSTON ! WE GOT AN EXCETPITON !
'topScoringIntent'
127.0.0.1 - - [04/Jun/2018 17:28:12] "POST /chat HTTP/1.1" 200 -
{'error': 'Unable to initialize persistor'}
HOUSTON ! WE GOT AN EXCETPITON !
'topScoringIntent'
127.0.0.1 - - [04/Jun/2018 17:29:13] "POST /chat HTTP/1.1" 200 -

在我启动的终端上 python -m rasa_nlu.server --path ~/Programing/Rasa/myflaskapp/models/nlu/ :

(myFlaskAppenv) mike@mike-thinks:~/Programing/Rasa/myflaskapp$ python -m rasa_nlu.server --path ~/Programing/Rasa/myflaskapp/models/nlu/
2018-06-04 17:29:06+0100 [-] Log opened.
2018-06-04 17:29:06+0100 [-] Site starting on 5000
2018-06-04 17:29:06+0100 [-] Starting factory <twisted.web.server.Site object at 0x7fdec5825f60>
2018-06-04 17:29:13+0100 [-] 2018-06-04 17:29:13 WARNING rasa_nlu.project - Using default interpreter, couldn't fetch model: Unable to initialize persistor
2018-06-04 17:29:13+0100 [-] 2018-06-04 17:29:13 ERROR __main__ - Unable to initialize persistor
2018-06-04 17:29:13+0100 [-] Traceback (most recent call last):
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/rasa_nlu/server.py", line 241, in parse
2018-06-04 17:29:13+0100 [-] self.data_router.parse, data))
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/twisted/python/threadpool.py", line 250, in inContext
2018-06-04 17:29:13+0100 [-] result = inContext.theWork()
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/twisted/python/threadpool.py", line 266, in <lambda>
2018-06-04 17:29:13+0100 [-] inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/twisted/python/context.py", line 122, in callWithContext
2018-06-04 17:29:13+0100 [-] return self.currentContext().callWithContext(ctx, func, *args, **kw)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/twisted/python/context.py", line 85, in callWithContext
2018-06-04 17:29:13+0100 [-] return func(*args,**kw)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/rasa_nlu/data_router.py", line 241, in parse
2018-06-04 17:29:13+0100 [-] model)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/rasa_nlu/project.py", line 118, in parse
2018-06-04 17:29:13+0100 [-] interpreter = self._interpreter_for_model(model_name)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/rasa_nlu/project.py", line 197, in _interpreter_for_model
2018-06-04 17:29:13+0100 [-] metadata = self._read_model_metadata(model_name)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/rasa_nlu/project.py", line 212, in _read_model_metadata
2018-06-04 17:29:13+0100 [-] self._load_model_from_cloud(model_name, path)
2018-06-04 17:29:13+0100 [-] File "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/rasa_nlu/project.py", line 250, in _load_model_from_cloud
2018-06-04 17:29:13+0100 [-] raise RuntimeError("Unable to initialize persistor")
2018-06-04 17:29:13+0100 [-] RuntimeError: Unable to initialize persistor
2018-06-04 17:29:13+0100 [-] "127.0.0.1" - - [04/Jun/2018:16:29:13 +0000] "GET /parse?q=Hi HTTP/1.1" 500 47 "-" "python-requests/2.18.4"

这里是app.py中涉及聊天机器人消息处理的部分,如果还有更多需要请告诉我,但我认为这不是最重要的:

@app.route('/chat',methods=["POST"])
def chat():
try:
user_message = request.form["text"]
response = requests.get("http://localhost:5000/parse",params={"q":user_message})
response = response.json()
entities = response.get("entities")
topresponse = response["topScoringIntent"]
intent = topresponse.get("intent")
print("Intent {}, Entities {}".format(intent,entities))
if intent == "gst-info":
response_text = gst_info(entities)# "Sorry will get answer soon" #get_event(entities["day"],entities["time"],entities["place"])
elif intent == "gst-query":
response_text = gst_query(entities)
else:
response_text = get_random_response(intent)
return jsonify({"status":"success","response":response_text})
except Exception as e:
print("HOUSTON ! WE GOT AN EXCETPITON !")
print(e)
return jsonify({"status":"success","response":"Sorry I am not trained to do that yet..."})

所以错误来自 project.py 中的 load_model_from_cloud :

...
class Project(object):
def __init__(self,
component_builder=None,
project=None,
project_dir=None,
remote_storage=None):
self._component_builder = component_builder
self._models = {}
self.status = 0
self._reader_lock = Lock()
self._loader_lock = Lock()
self._writer_lock = Lock()
self._readers_count = 0
self._path = None
self._project = project
self.remote_storage = remote_storage
...
def _load_model_from_cloud(self, model_name, target_path):
try:
from rasa_nlu.persistor import get_persistor
p = get_persistor(self.remote_storage)
if p is not None:
p.retrieve(model_name, self._project, target_path)
else:
raise RuntimeError("Unable to initialize persistor")
except Exception as e:
logger.warn("Using default interpreter, couldn't fetch "
"model: {}".format(e))
raise # re-raise this exception because nothing we can do now

所以问题是我没有设置remote_storage。我什至不知道这是什么!

<小时/>

附录:

Rasa NLU 版本:

rasa 核心:0.9.0a3
拉萨-nlu:0.12.3

操作系统:Linux 16.04

模型配置文件内容:

slots:
location:
type: text
mood:
type: text
information:
type: text
adjective:
type: text

# intention the bot is able to recognize from the sentences
intents:
- greet
- goodbye
- inform

# entities he may be able to extract
entities:
- location
- mood
- information
- adjective

# actions the bot can take
actions:
- utter_greet
- utter_goodbye
- utter_ask_location
- actions.ActionWeather
- utter_joy
- utter_fear
- utter_anger
- utter_sadness
- utter_disgust
- utter_shame
- utter_guilt

templates:
utter_greet:
- 'Hello! How can I help?'
utter_goodbye:
- 'Talk to you later.'
- 'Bye bye :('
utter_ask_location:
- 'In what location?'
utter_joy:
- 'Am so happy for you'
utter_fear:
- 'you shouldn be afraid'
utter_anger:
- 'Calm down, everything gonna be alright'
utter_sadness:
- 'be a tough guy'
utter_disgust:
- 'I understand, this is disgusting, we should get over it'
utter_shame:
- 'Ridicule does not kill'
utter_guilt:
- 'You must not feel guilty, feel proud'

[image of the chatbot] 3

最佳答案

不要使用相对路径,而是尝试使用像 home/mike/Programming... 这样的完整路径,因为 Rasa 会检查您的路径是否是操作系统中的有效目录

关于python - 无法初始化 Flask 应用程序和 rasa_nlu.server 之间的持久器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50687057/

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