ml2021
(Maria)
1
Hi all,
I want to create response variations from a custom action in actions.py
, instead of domain.yml
.
I tried to create a list inside def run
:
response = ['hello!', 'hi there', 'hi again']
and then used a random.shuffle function to send back a response:
dispatcher.utter_message(
text = random.shuffle(response),
)
This does not work and I get None
in response.
How can I solve this?
ChrisRahme
(Chris Rahmé)
2
Hey Maria,
This is more of a Python question than a Rasa one.
random.shuffle()
(try it) shuffles a list, meaning it reorganizes its items. It does not randomly take one element.
Instead, you can shuffle the list and take the first element:
dispatcher.utter_message(text = random.shuffle(response)[0])
or use random.choice()
(try it) which is the method you’re looking for:
dispatcher.utter_message(text = random.choice(response))
1 Like
ml2021
(Maria)
3
Silly of me to think it was related to the dispatcher element… Thanks for the heads up @ChrisRahme!
1 Like