Hi everyone! This is my 1st post here,
I am trying to run a physical robot that figures out the next action it should take based on Rasa stories. But I am using a different NLU because my project specifies it so (multi-modal input rather than just a string of text).
I’m having trouble understanding how to implement this using Python only, and your help would be greatly appreciated. The idea is that a command like:
$ python run.py
should run my RasaCore and execute the Actions as well.
My trouble is in understanding what I should make on the code to get what I need. That is, I want to input the intent myself and extract the next action, as well as to progress the state of the conversation (dialog management).
Do I need to create an Agent with the loaded model and then from there create a processor?
Do I need to create a DialogStateTracker?
If I trained my model with the policies, do I need to tell the Agent again which policies in the policies=() parameter?
Pretty confussed, help me please!
Hi @EllisonFord, welcome to the community!
using Core is an interesting use case! May I ask why you are using a different NLU?
A couple of resources to help you:
I could image in a workflow like:
- Running your NLU and Rasa a separate services
- Whenever your NLU detected an intent / entities
- update the tracker in Rasa using HTTP API
- predict next action using HTTP API
What do you think?
1 Like
Hi @Tobias_Wochinger, thank you for your reply.
I’m doing a robotics master thesis, where the robot will have some predicting capabilities based on Rasa Stories. I will be glad to share a video or other details when the project is done. You can see a user story I made that shows what the end product may look like: UserStory1.pdf (3.6 MB)
For the problem I had, I managed to find a solution; albeit a rough patch. I trained a NLU to just output the input, as seen below. And then I’m running a Core+NLU trained model to figure out the next part. So my current NLU looks like:
intent:agree_intent
intent:finish_the_work
intent:report_intent
And trained using the “KeywordIntentClassifier” pipeline and that seemed to do it.
Though I do feel like there had to be a better way at doing this. Aka, just using Core.
Tobias, do you have any good examples of how to run the Rasa actions.py script from Python? That would be awfully useful right now.
Very kind regards
I’m doing a robotics master thesis, where the robot will have some predicting capabilities based on Rasa Stories.
That sounds like a great thesis! I wish you all the best!
do you have any good examples of how to run the Rasa actions.py script from Python? That would be awfully useful right now.
Sorry, can you attach a github link which module you mean?
I haven’t tried it out, but you could train a rasa bot without nlu data and then do
from rasa.run import create_agent
agent = create_agent(model_path)
from rasa.core.interpreter import RegexInterpreter
agent.interpreter = RegexInterpreter()
agent.handle_message("/agree_intent")
Without python you’d just send a message with a /<intent_name>
to the bot (without having any nlu data) to one of the connector endpoints.
1 Like
Hi @Tobias_Wochinger, that worked like a charm!
And I managed to run the Rasa Action server from the py code by:
import rasa_sdk.endpoints
rasa.sdk_endpoint.run('actions')
Now my problem is that once it starts running it never stops! Ctrl+C
doesn’t seem to do a thing about it. Do you know a solution for this?
I really appreaciate your replies btw
Glad it works!
import rasa_sdk.endpoints
rasa.sdk_endpoint.run('actions')
Shouldn’t it be
import rasa_sdk.endpoint # without s
rasa_sdk.endpoint.run('actions') # instead of rasa.sdk
Now my problem is that once it starts running it never stops! Ctrl+C
doesn’t seem to do a thing about it. Do you know a solution for this?
I saw it’s a an async
function. Are you creating a loop and running it with loop.run_until_complete(agent.handle(...))
or how are you running it?
Glad that I can help you
1 Like
Hey there, im using this code block but the output is a is empty list. Im using rasa 2.8.34.
import asyncio
from rasa.core.agent import Agent , create_agent
from rasa.shared.nlu.interpreter import RegexInterpreter
from rasa.core.channels.channel import OutputChannel, UserMessage
model_path = "models/core-20230504-153346.tar.gz"
agent = create_agent(model_path)
# from rasa.core.interpreter import RegexInterpreter
agent.interpreter = RegexInterpreter()
async def handle_message():
user_message = UserMessage("/intent_cancel_appointment", sender_id="user1")
return await agent.handle_message(user_message)
# Run the async function
response = asyncio.run(handle_message())
print(response)