sklep-internetowy-systemy-d.../chatbot/modules/strategy.py

29 lines
1.3 KiB
Python

from modules.nlu import Act, Slot
import random
class DialoguePolicy:
def next_action(self, dst):
if not dst.state['belief_state']['order-complete']:
user_intent = dst.state['act']
if user_intent == "inform":
empty_slot = dst.find_random_empty_slot()
return Act(intent="request", slots=[Slot(name=empty_slot, value='')])
elif user_intent == "request":
if dst.state['slot_names']:
if 'price' in dst.state['slot_names']:
slot = 'price'
else:
slot = random.choice(dst.state['slot_names'])
return Act(intent="inform", slots=[Slot(name=slot, value='')])
else:
return Act(intent="canthelp", slots=[Slot(name='unknown', value='')])
elif user_intent == "bye":
return Act(intent="bye", slots=[Slot(name='', value='')])
elif user_intent == "welcomemsg":
return Act(intent="welcomemsg", slots=[Slot(name='', value='')])
else:
return Act(intent="canthelp", slots=[Slot(name='unknown', value='')])
else:
return Act(intent="inform", slots=[Slot(name='confirmation', value='Zamówienie złożono poprawnie.')])