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

29 lines
1.3 KiB
Python
Raw Normal View History

2024-06-11 18:10:51 +02:00
from modules.nlu import Act, Slot
import random
2024-05-07 21:40:14 +02:00
2024-06-11 01:56:44 +02:00
class DialoguePolicy:
2024-06-11 18:10:51 +02:00
def next_action(self, dst):
if not dst.state['belief_state']['order-complete']:
user_intent = dst.state['act']
2024-06-11 01:56:44 +02:00
if user_intent == "inform":
empty_slot = dst.find_random_empty_slot()
2024-06-11 18:10:51 +02:00
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'])
2024-06-11 18:10:51 +02:00
return Act(intent="inform", slots=[Slot(name=slot, value='')])
2024-06-11 01:56:44 +02:00
else:
2024-06-11 18:10:51 +02:00
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='')])
2024-06-11 18:10:51 +02:00
else:
return Act(intent="canthelp", slots=[Slot(name='unknown', value='')])
2024-06-11 01:56:44 +02:00
else:
2024-06-11 18:10:51 +02:00
return Act(intent="inform", slots=[Slot(name='confirmation', value='Zamówienie złożono poprawnie.')])