# Testing custom component

**URL:** <https://forum.rasa.com/t/testing-custom-component/26957>\
**Category:** Rasa Open Source\
**Created:** [April 2, 2020, 2:26pm UTC](https://forum.rasa.com/t/testing-custom-component/26957 "2020-04-02T14:26:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Learner](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@Learner](https://forum.rasa.com/u/Learner)\
**Post date:** [April 2, 2020, 2:26pm UTC](https://forum.rasa.com/t/testing-custom-component/26957/1 "2020-04-02T14:26:25Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![samscudder](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/samscudder/32/4466_2.png) [@samscudder](https://forum.rasa.com/u/samscudder)\
**Post date:** [April 2, 2020, 3:17pm UTC](https://forum.rasa.com/t/testing-custom-component/26957/2 "2020-04-02T15:17:19Z")

</div>

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:

```auto
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'])

```

---

<div class="post-metadata">

**Author:** ![Learner](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@Learner](https://forum.rasa.com/u/Learner)\
**Post date:** [April 2, 2020, 4:22pm UTC](https://forum.rasa.com/t/testing-custom-component/26957/4 "2020-04-02T16:22:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![samscudder](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/samscudder/32/4466_2.png) [@samscudder](https://forum.rasa.com/u/samscudder)\
**Post date:** [April 2, 2020, 8:20pm UTC](https://forum.rasa.com/t/testing-custom-component/26957/5 "2020-04-02T20:20:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Learner](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@Learner](https://forum.rasa.com/u/Learner)\
**Post date:** [April 3, 2020, 7:20am UTC](https://forum.rasa.com/t/testing-custom-component/26957/6 "2020-04-03T07:20:11Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![samscudder](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/samscudder/32/4466_2.png) [@samscudder](https://forum.rasa.com/u/samscudder)\
**Post date:** [April 3, 2020, 11:53am UTC](https://forum.rasa.com/t/testing-custom-component/26957/7 "2020-04-03T11:53:42Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

**Author:** ![Learner](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@Learner](https://forum.rasa.com/u/Learner)\
**Post date:** [April 3, 2020, 12:57pm UTC](https://forum.rasa.com/t/testing-custom-component/26957/8 "2020-04-03T12:57:58Z")

</div>

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…
