2

I installed the rasa-demo code sample. For turning on the rasa API, I did:

user@User:~/rasa-demo ‹master*›$ rasa run
No chat connector configured, falling back to the REST input channel. To connect your bot to another channel, read the docs here: https://rasa.com/docs/rasa/user-guide/messaging-and-voice-channels
2020-06-19 13:20:02 INFO     root  - Starting Rasa server on http://localhost:5005
2020-06-19 13:20:08 INFO     absl  - Using /var/folders/h5/9rj1zn8x4s59bk_mg_ktzv740000gn/T/tfhub_modules to cache modules.
2020-06-19 13:20:08 INFO     absl  - Downloading TF-Hub Module 'http://models.poly-ai.com/convert/v1/model.tar.gz'.
2020-06-19 13:20:26 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 22.35MB
2020-06-19 13:20:43 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 42.35MB
2020-06-19 13:21:02 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 82.35MB
2020-06-19 13:21:21 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 118.59MB
2020-06-19 13:21:40 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 148.59MB
2020-06-19 13:21:41 INFO     absl  - Downloaded http://models.poly-ai.com/convert/v1/model.tar.gz, Total size: 152.02MB
2020-06-19 13:21:41 INFO     absl  - Downloaded TF-Hub Module 'http://models.poly-ai.com/convert/v1/model.tar.gz'.
2020-06-19 13:22:14 INFO     root  - Rasa server is up and running.

How can I query as an API the chatbot? I would like be able to make a request and do the conversation through requests, instead of using the shell. So far, when I tried to make a curl to the rasa server:

In:

user@User:~ $ curl -XPOST localhost:5005/webhooks/rest/webhook -d '{"message":"hi"}'

Out:

[]%

On the rasa run server, I get this response:

2020-06-19 13:23:17 ERROR    rasa.core.actions.action  - Failed to run custom action 'action_greet_user'. Couldn't connect to the server at 'http://localhost:5055/webhook'. Is the server running? Error: Cannot connect to host localhost:5055 ssl:default [Connection refused]
2020-06-19 13:23:17 ERROR    rasa.core.processor  - Encountered an exception while running action 'action_greet_user'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
2020-06-19 13:24:04 ERROR    rasa.core.actions.action  - Failed to run custom action 'action_greet_user'. Couldn't connect to the server at 'http://localhost:5055/webhook'. Is the server running? Error: Cannot connect to host localhost:5055 ssl:default [Connection refused]
2020-06-19 13:24:04 ERROR    rasa.core.processor  - Encountered an exception while running action 'action_greet_user'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.

It is not working. What is the correct way to request Rasa server as an API? After reading the docs, it is not clear to me how to make correct usage of the API.

I also tried this:

In:

import requests

response = requests.get('http://localhost:5005/webhooks/rest/webhook') 
print(response) 
print(response.headers) 
print(response.content)

Out:

<Response [405]>
{'Connection': 'keep-alive', 'Keep-Alive': '5', 'Allow': 'POST', 'Access-Control-Allow-Credentials': 'true', 'Content-Length': '60', 'Content-Type': 'text/plain; charset=utf-8'}
b'Error: Method GET not allowed for URL /webhooks/rest/webhook'
tumbleweed
  • 4,624
  • 12
  • 50
  • 81

5 Answers5

5

I end up figuring out that this is how you request the end point:

localhost:5005/model/parse -s -d '{ "text": "hi" }'

The documentation should be clearer.

tumbleweed
  • 4,624
  • 12
  • 50
  • 81
2

Try starting rasa server with: rasa run --enable-api it worked for me.

Mavic More
  • 99
  • 1
  • 3
1

To access the REST endpoint, you should use the rasa run command instead. That will start a Rasa server, enabling any channels you've defined in your credentials file (if that file isn't provided, Rasa will enable the REST channel by default).

Then you can query the endpoint as you've described in your post, see more details on the format of the request here.

  • I read the docs that you shared. However, when I do: `curl http://localhost:5005/webhooks/rest/webhook/` I get as response: `Error: Method GET not allowed for URL /webhooks/rest/webhook%` and `sanic.exceptions.MethodNotSupported: Method GET not allowed for URL /webhooks/rest/webhook/`. What is the format of the curl, the docs dont mention anything. Thanks – tumbleweed Jun 16 '20 at 15:18
  • 1
    ah, it should be a post request, like you did in your original question `curl -XPOST localhost:5005/webhooks/rest/webhook -d '{"message":"hi"}'` – Akela Drissner Jun 18 '20 at 07:40
  • I updated the question. When I do that post curl, I get: `2020-06-19 13:24:04 ERROR rasa.core.processor - Encountered an exception while running action 'action_greet_user'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.` and `[]%` – tumbleweed Jun 19 '20 at 18:32
  • 2
    Feel free to open an issue on our github repo for any enhancements to the docs you would like to see. The error you're receiving means that your action has an error in it, or your action server isn't running. – Akela Drissner Jun 24 '20 at 13:45
1

Make sure you are in rasa project directory, before running rasa commands.

1
@app.route('/result', methods=['POST', 'GET'])
def res_json():
    if request.method == "POST":
        text = request.form.get('query')
        payload = {"sender": "Rasa", "text": text}
        headers = {'content-type': 'application/json'}
        response = requests.post('http://localhost:5005/model/parse', json=payload, headers=headers)
        result = response.json()
        return result
Chandan Gupta
  • 684
  • 4
  • 11