Unable to run rasa agent inside rasa core server

298 Views Asked by At

I am trying to load and run a rasa model inside my nlu server in rasa 3, however, after loading the model with the Agent I am unable to perform inference with the model.

    @DefaultV1Recipe.register(
        [DefaultV1Recipe.ComponentType.INTENT_CLASSIFIER], is_trainable=False
    )
    class MyCustomComponent(GraphComponent, EntityExtractorMixin):
    
        def __init__(self, config):
            model_path = "model_path"
            self.model = Agent.load(model_path=model_path)
    
        def process(self, messages):
            for message in messages:
                result = self.model.parse_message(message.get("text"))
                message.set(
                    "my_field",
                    result.get("intent"),
                    add_to_output=True,
                )
            return messages

Everytime the parse_message method executes, it returns a coroutine, which I am not sure how to extract the results from.

And, if I try to go via asyncio.get_running_loop() and loop.run_until_complete method, I get the following error.

asyncio.run() cannot be called from a running event loop

Any ideas on how can this problem be solved?

Thanks!

1

There are 1 best solutions below

0
On

You should await your function call, since that method is async

result = await self.model.parse_message(message.get("text"))