发送CURL命令并从Flask页面检索响应

问题描述 投票:0回答:1

当我启动此命令时:

$python -m rasa_core.server 
-d <DIALOGUE_MODEL_PATH> 
-u <NLU_MODEL_PATH> 
--debug 
-o out.log 
--cors *

当我使用curl -XPOST命令的终端时,我得到以下预期结果。

$ curl -XPOST localhost:5005/conversations/default/respond -d '{"query":"Hello"}'
[{"recipient_id": "default", "text": "Hello! How can I help?"}]

服务器似乎运行良好:

2018-06-06 09:28:14+0100 [-] 2018-06-06 09:28:14 DEBUG    rasa_core.tracker_store  - Creating a new tracker for id 'default'.
2018-06-06 09:28:15+0100 [-] /home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/lib/python3.5/site-packages/sklearn/preprocessing/label.py:151: builtins.DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
2018-06-06 09:28:15+0100 [-] 2018-06-06 09:28:15 DEBUG    rasa_core.processor  - Received user message 'I am sad' with intent '{'name': 'inform', 'confidence': 0.9091038037055945}' and entities '[{'start': 5, 'entity': 'mood', 'value': 'sad', 'extractor': 'ner_crf', 'end': 8, 'confidence': 0.5274867092381141}]'
2018-06-06 09:28:15+0100 [-] 2018-06-06 09:28:15 DEBUG    rasa_core.processor  - Logged UserUtterance - tracker now has 3 events
2018-06-06 09:28:15+0100 [-] 2018-06-06 09:28:15 DEBUG    rasa_core.processor  - Current slot values: 
2018-06-06 09:28:15+0100 [-]    location: None
2018-06-06 09:28:15+0100 [-]    adjective: None
2018-06-06 09:28:15+0100 [-]    information: None
2018-06-06 09:28:15+0100 [-]    mood: sad
2018-06-06 09:28:15+0100 [-] 2018-06-06 09:28:15 DEBUG    rasa_core.policies.memoization  - Current tracker state [
2018-06-06 09:28:15+0100 [-]    None
2018-06-06 09:28:15+0100 [-]    None
2018-06-06 09:28:15+0100 [-]    [('intent_inform', 1), ('entity_mood', 1), ('slot_mood_0', 1), ('prev_action_listen', 1)]]
2018-06-06 09:28:15+0100 [-] 2018-06-06 09:28:15 DEBUG    rasa_core.policies.memoization  - Used memorised next action '9'
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.policies.ensemble  - Predicted next action 'utter_sadness' with prob 1.00.
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.processor  - Bot utterance 'BotUttered(text: be a tough guy, data: null)'
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.processor  - Action 'utter_sadness' ended with events '[]'
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.policies.memoization  - Current tracker state [
2018-06-06 09:28:19+0100 [-]    None
2018-06-06 09:28:19+0100 [-]    [('intent_inform', 1), ('entity_mood', 1), ('slot_mood_0', 1), ('prev_action_listen', 1)]
2018-06-06 09:28:19+0100 [-]    [('intent_inform', 1), ('entity_mood', 1), ('slot_mood_0', 1), ('prev_utter_sadness', 1)]]
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.policies.memoization  - Used memorised next action '0'
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.policies.ensemble  - Predicted next action 'action_listen' with prob 1.00.
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.processor  - Action 'action_listen' ended with events '[]'
2018-06-06 09:28:19+0100 [-] 2018-06-06 09:28:19 DEBUG    rasa_core.processor  - Current topic: None
2018-06-06 09:28:19+0100 [-] "127.0.0.1" - - [06/Jun/2018:08:28:13 +0000] "POST /conversations/default/respond HTTP/1.1" 200 55 "-" "curl/7.47.0"

但是当我尝试通过图形界面发送消息时,我得到一个例外:

Expecting value: line 1 column 1 (char 0)
127.0.0.1 - - [06/Jun/2018 09:33:46] "POST /chat HTTP/1.1" 200

而这只来自Rasa服务器终端:

2018-06-06 09:41:14+0100 [-] "127.0.0.1" - - [06/Jun/2018:08:41:13 +0000] "GET /parse?q=Hi HTTP/1.1" 404 233 "-" "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:5005/parse",params={"q":user_message})
        response = response.json()
        print("response :\n",response) 
        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:
            get_random_response = lambda intent:random.choice(intent_response_dict[intent])
            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..."})

**因此,我只是在Flask创建的图形页面上寻找使用CURL命令获得的相同答案。 **

目前我只得到:

introducir la descripción de la imagen aquí

python curl rasa-core
1个回答
1
投票

你正在做一个get而不是post,它期望一个直接的字符串作为数据参数,而不是一个JSON对象作为param参数。我将我想解释的文本传递给这样的方法

   def apiai_text_request(self, text):
    request_text = '{"q":"'+text+'"}'
    result = requests.post("http://localhost:5000/parse", data = request_text)
    return result.json()
© www.soinside.com 2019 - 2024. All rights reserved.