Can Any Tell me how to create chat bot which should not repeat same answer if the same question is repeated Basically As per my knowledge I can use multiple response text for every utter_response but In this also there is no surety that we will get different response everytime if the same is asked since it pick random text from response from domain.yml. So Can anybody suggest how can I acheive it.
The same question was asked 2 weeks ago:
Hope it helps
So we need create custom action for every intent Correct ? Is there any way to create one common custom action for every intent? Thank You
Why would you want to do this? It completely removes the AI part of stories if all intents will call the same action.
But you can all do it in one action if you really want to…
from random import randrange
import json
class ActionReply(Action):
def name(self):
return 'action_reply'
def run(self, dispatcher, tracker, domain):
intent = tracker.latest_message['intent']
replies = {
'greet': [ # for intent greet
'hi!', # 0
'happy to see you.' # 1
'hope you\'re having a nive day.' # 2
],
'goodbye': [ # for intent goodbye
'bye!', # 0
'hope to see you soon.' # 1
'have a nice day.' # 2
]
}
already_uttered_all = json.loads(tracker.get_slot('already_uttered')) # Dictionary of intents and their replies
already_uttered = already_uttered_all[intent] # For example [0, 2] means the first and third sentences were already uttered for that intent
if len(already_uttered) >= len(replies[intent]): # If all the sentences were already uttered, reset
already_uttered = [] # Reset the slot
random_index = None
while (random_index is None) or (random_index not in already_uttered): # Do this until we get a random_index that was not uttered
random_index = randrange(len(goodbyes))
utterance = goodbyes[random_index]
already_uttered_all[intent].append(random_index)
return [SlotSet('already_uttered', json.dumps(already_uttered_all))]
You could create your own NLG Server
Hi Chris,
I have a question about this, if you write an action like this. What causes it to trigger for every intent?