我有一个网络应用程序聊天和一个作为聊天机器人的 Rasa 服务器,我希望聊天机器人处理从第一个接收到的消息。
在端口 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-core:0.9.0a3
rasa-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'