无法初始化Flask应用程序和rasa_nlu.s之间的persistor

2024-04-26 21:33:28 发布

您现在位置:Python中文网/ 问答频道 /正文

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

在8000端口和rasa上启动应用程序后_nlu.服务器在端口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/的终端上:

^{pr2}$

以下是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
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'

[image of the chatbot]3


Tags: totextselfprojectnoneappgetresponse