首页 文章

无法在Flask app和rasa_nlu.server之间初始化persistor

提问于
浏览
1

我有一个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 -

在我发布_1185207_的终端上:

(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 version

rasa-core:0.9.0a3
rasa-nlu:0.12.3

Operating system :Linux 16.04

Content of model configuration file

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

1 回答

  • 1

    考虑到Rasa将检查您的路径是否是OS中的有效目录,而不是使用相对路径尝试使用像_1685220这样的完整路径

相关问题