Accessing RASA NLU only server from python code using API

I want to use Rasa NLU server only for my custom dialogue management , which is written in a python code. For that i want to post messages to the nlu server and get the intent rankings. I tried -

text=str(input("Enter the message"))
payload = json.dumps({"sender": "Rasa","message": text})
headers = {'content-type': 'application/json'}
response = requests.request("POST",'', json=payload, headers=headers)
response = response.json()
print("response :\n",response)

However it throws an error, -

response : {‘version’: ‘2.8.18’, ‘status’: ‘failure’, ‘message’: ‘An unexpected error occurred. Error: string indices must be integers’, ‘reason’: ‘ParsingError’, ‘details’: {}, ‘help’: None, ‘code’: 500}

But if the payload is -

payload = {'text':'hi how are you?'}
headers = {'content-type': 'application/json'}
r ='', json=payload, headers=headers)

then i get the list of intent rankings properly.

The sender id is necessary as I am trying to manage dialogues externally through my code. Please help

Hi @sandeeppandey456 ,

The following should work, it looks like the issue was that you used "message" in your payload instead of "text":

text = str(input("Enter the message"))
payload = {"sender": "Rasa","text": text})
headers = {'content-type': 'application/json'}
response ='', json=payload, headers=headers)
response = response.json()
print("response :\n",response)

That being said, I’m not sure the server will send back the sender_id bit. You could try with message_id: Rasa Open Source Documentation

Alternatively, you could load a NLU model directly in your code: see Using nlu model with Interpreter.load in Rasa 3.0 - #8 by isgaal

Hope that helps

1 Like