Testing custom component

Hello everybody,

I am new to Rasa, and I have the following question.

I have introduced a new custom component to my code, that adds a new entity called “name” to my already existent entities.

I started writing a python code that sends a request to the server, and prints the values of my entities, but I understand that the new entity “name” that I have introduced is not recognized.

Is there any way, to get the value of the new entity ?

If you send the message to Rasa by API (using requests), you can read the slot values from the tracker store. I use mongodb to persist the tracker store, (see the endpoints.yml file), so I can access it directly using pymongo.

Here’s how I read the slot values:

from pymongo import MongoClient

...

mongocli = MongoClient('mongodb://mongo:27017')

#rasa db is the same as set in the endpoints.yml tracker store.
rasa = mongocli['rasa']
conversations_iago = rasa['conversations']

# tester is the user_id used to submit the messages
user_id = 'tester'

slots_found = conversations_iago.find({ 'sender_id': str(user_id) }, { 'slots': 1 } )

for row in slots_found:
        slots = dict(row['slots'])

Hello samscudder thank you so much for your answer, but I think I didn’t explain what I want to do very well.

So I have a list of sentences called “examples”.

What I need to do is simply print the value of the new entity “name” introduced by my custom component.

The thing is that, the new entity “name” is not recognized.

It looks like no entity extraction is happening… Are you hitting the right intent? Try printing out or logging the value of resp_json to see what Rasa is returning.

PS: I guess you know this, but the loop is wrong. It should be for i in range(0, len(examples)): or for example in examples: and then you’d use params = { "text": example } (example instead of examples[i]).

The way it stands, you’re throwing a 'int' object is not iterable error.

Yes I have used the same syntaxe for params, I edited my code in order to explain what is happening.

The code I am using extracts the other entities (the ones I have defined in the nlu file), my problem is that it doesn’t recognize the one I introduced in my custom component. I want my code to be able to identify all of the entities including the old and new one.

Maybe the problem is in the way I introduce my new entity, in my custom component I simply introduce it inside the process() method like the following:

def process(self, message: Message, **kwargs: Any) -> None:

        entities = message.get(ENTITIES)

        for entity in entities:

            if entity['entity'] == 'person':

                #here I do some calculations, because the entity person has a hidden name inside of it

                ...
                    
                entity['name']=result

So it prints out when I use the rasa shell nlu command only.

I think I understand a bit better what you’re trying to do. I thought that by custom component meant an action. Sorry about that.

I looked over the DIETClassifier, and noticed that it does this after extracting the entities:

message.set(ENTITIES, entities, add_to_output=True)

Do you have something like this in your code after setting entity[‘name’]?

I am the one who should be apologizing, I just realized that the way I introduce my entity is wrong. The whole conception of my code should be changed…