Intent is null while calling the Rasa NLU Server

I am using Rasa NLU 0.12.3

Using @Juste nlu_model.py, I can get the intent properly.

Now I am creating a nodeJS service where I need to know the current intent. So I am running the NLU server as

python -m rasa_nlu.server --path /PATH_TO_BOT/nlu_model.py

And in the nodeJS service doing below:

var URLRasaNLU = 'http://localhost:5000/parse?q='
var messageToRasa = "show upcoming renewals"
var NLUModelPath = '&model=PATH_TO_BOT'
    
var options = {
                      url: URLRasaNLU+messageToRasa+NLUModelPath
                  };

                  function callback(error, response, body) {
                      if (!error && response.statusCode == 200) {
                          var result = JSON.parse(body);
                          console.log(result)
                          console.log(result.intent.name);
                      }
                  }

                  request(options, callback);

But this is returning “null” intent

What am I missing?

Few things could be wrong here

  1. First why you are pointing to a python file in your path. path should determine where your projects are stored. Typically they are several models per project. in your case if you have trained without mentioning a project then the project is default. so path should be the path to where your projects are stored
  2. the model parameters in your query string should point to a model name instead of a model path
  3. CORS by default blocks all domain

Take a look here at all the parameters

Hey @nahidalam. Souvik is absolutely right, the first thing you should change is the path you provide when you start the server. It shouldn’t point to the python file which you used to train the model. Instead, the path should point to the actual model (which if you are following the weatherbot tutorial is /models/dialogue/ for a dialogue management model and /models/nlu/default/weathernlu for the nlu model).

Can you give an example? The reason I have a file path because thats the only way I found the intent retrieval from nlu server working. I tried what @souvikg10 and @Juste mentioned but couldn’t make it work. What am I missing?

What I tried (that didnt work)

$python -m rasa_nlu.server --path /PATH/renewalBot/models/nlu/default/renewalnlu/

$curl --request POST --url http://localhost:5000/parse --header 'content-type: application/json' --data '{ "q": "hello", "project": "/PATH/renewalBot","model":"/PATH/renewalBot/models/nlu/default/renewalnlu/"}' | python -mjson.tool

Throws error: "error": "No project found with name '/PATH/renewalBot'."

Note: I did NOT train the model using nlu server.

What works (not really …)

$python -m rasa_nlu.server --path /PATH/renewalBot/nlu_model.py

var request = require('request');

var options = {
    url: 'http://localhost:5000/parse?q=hello&model=/PATH/renewalBot/models/nlu/default/renewalnlu'
   
    };

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        var result = JSON.parse(body);
        console.log(result.intent.name);
    }
}

request(options, callback);

The above worked fine as long as the query is hello but if I change the query, it doesn’t return any intent. Suggestion?

Can you share the script on how did you train the model, the script. I think you have a project mismatch.

@souvikg10 here is the code

def train_nlu(data, configuration, model_dir, model_name):
	training_data = load_data(data)
	trainer = Trainer(config.load(configuration))
	trainer.train(training_data)
	model_directory = trainer.persist(model_dir, fixed_model_name = model_name)
	return model_directory

if __name__ == '__main__':
	model_directory = train_nlu('./data/data.json', 'config_spacy.yml', './models/nlu', 'renewalnlu')

Okay so your models are stored in models/nlu

python -m rasa_nlu.server --path /PATH/models/nlu --config config_spacy.yml

your model name is not the same as your project name. in the case of your training your project name is default.

@souvikg10 ok so how do I solve this? I tried below but no luck

$python -m rasa_nlu.server --path /PATH/renewalBot/models/nlu/default/renewalnlu/

curl --request POST --url http://localhost:5000/parse --header 'content-type: application/json' --data '{ "q": "hello", "project": "default","model":"/PATH/renewalBot/models/nlu/"}' | python -mjson.tool

Also I tried below

$python -m rasa_nlu.server --path /PATH/renewalBot/ --config config_spacy.yml

But says no such file as config_spacy.yml although I have that file in that directory. So maybe something related to environment I am missing?

@nahidalam you have to try the command i provided above

path is not where your model is but rather where your projects are

you have to provide absolute path for your config though i recently checked the latest version and you don’t need to provide the config anymore

 $python -m rasa_nlu.server --path /PATH/renewalBot/models/nlu
curl --request POST --url http://localhost:5000/parse --header 'content-type: application/json' --data '{ "q": "hello"}' | python -mjson.tool

this is all you need. Since in your training script, you don’t provide a model name nor a project name, it will consider the default project name as ‘default’ and model name as ‘model_timestamp’ and will look under the folder where you have kept the projects which you have mentioned in your server run command.

Run the above and check again

Getting error

"error": "Unable to initialize persistor"

I guess try with the config

–config PATH/renewalbot/yourconfigname.yml

why iam getting only null and greet intents.
I used python -m rasa_nlu.server --path projects
to start server but i am unable to load my intents instead it is fall backing only to greet and null intents.Between what is projects at the end of above command actually mean