Невозможно инициализировать персистор между приложением Flask и rasa_nlu.server
У меня есть чат с веб-приложением и сервер Rasa, являющийся чат-ботом, и я хочу, чтобы он обрабатывал сообщения, полученные от первого.
После запуска приложения на порту 8000 и rasa_nlu.server на порту 5000 у меня возникают сложности с тем, чтобы сервер обрабатывал сообщения. Действительно, на 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..."})
Таким образом, ошибка была из load_model_from_cloud в project.py:
...
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-core: 0.9.0a3
раса-нлу: 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'
1 ответ
Вместо использования относительного пути попробуйте использовать полный путь, например home/mike/Programming...
учитывая, что Rasa проверит, является ли ваш путь действительным каталогом в ОС