dp mockup

This commit is contained in:
Anna Śmigiel 2024-06-11 01:56:44 +02:00
parent 1926681255
commit 253320ce1d
2 changed files with 28 additions and 7 deletions

View File

@ -13,7 +13,7 @@ class DialogStateMonitor:
'delivery_method': {}, 'delivery_method': {},
'payment_method': {}, 'payment_method': {},
'email': {}, 'email': {},
'order-complete': False, 'order-completed': False,
}, },
act='', act='',
slot_names=[]) slot_names=[])
@ -37,6 +37,11 @@ class DialogStateMonitor:
['item', 'address', 'card_nr', 'delivery_method', 'payment_method', 'email']) ['item', 'address', 'card_nr', 'delivery_method', 'payment_method', 'email'])
self.state['belief_state']['order-complete'] = all_filled self.state['belief_state']['order-complete'] = all_filled
def find_first_empty_slot(self):
for slot_name, slot_value in self.state['belief_state'].items():
if slot_name != 'order-completed' and self.is_value_empty(slot_value):
return slot_name
def update(self, act: UserAct) -> None: def update(self, act: UserAct) -> None:
print(act) print(act)
if act.intent == 'inform': if act.intent == 'inform':

View File

@ -1,8 +1,24 @@
import random from modules.nlu import UserAct, Slot
from numpy.random.mtrand import random
class DialogueStrategy: class DialoguePolicy:
@staticmethod def __init__(self, dst):
def decide_response(state: dict, responses) -> str: self.dialogue_state = dst.state
intent_responses = responses.get(state['last_intent'], ["Przepraszam, nie rozumiem. Możesz to powtórzyć?"])
return random.choice(intent_responses) def next_action(self):
if not self.dialogue_state['belief_state']['order-complete']:
user_intent = self.dialogue_state['act']
if user_intent == "inform":
empty_slot = dst.find_first_empty_slot()
return UserAct(intent="request", slots=[Slot(name=empty_slot, value='')])
if user_intent == "request":
if self.dialogue_state['slot_names']:
slot = random.choice(self.state['slot_names'])
return UserAct(intent="inform", slots=[Slot(name=slot, value='')])
else:
return UserAct(intent="inform", slots=[Slot(name='unknown', value='')])
if user_intent == "bye":
return UserAct(intent="bye", slots=[Slot(name='', value='')])
else:
return UserAct(intent= "inform", slots=[Slot(name='confirmation', value='Zamówienie złożono poprawnie.')])