dp mockup
This commit is contained in:
parent
1926681255
commit
253320ce1d
@ -13,7 +13,7 @@ class DialogStateMonitor:
|
||||
'delivery_method': {},
|
||||
'payment_method': {},
|
||||
'email': {},
|
||||
'order-complete': False,
|
||||
'order-completed': False,
|
||||
},
|
||||
act='',
|
||||
slot_names=[])
|
||||
@ -37,6 +37,11 @@ class DialogStateMonitor:
|
||||
['item', 'address', 'card_nr', 'delivery_method', 'payment_method', 'email'])
|
||||
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:
|
||||
print(act)
|
||||
if act.intent == 'inform':
|
||||
|
@ -1,8 +1,24 @@
|
||||
import random
|
||||
from modules.nlu import UserAct, Slot
|
||||
from numpy.random.mtrand import random
|
||||
|
||||
|
||||
class DialogueStrategy:
|
||||
@staticmethod
|
||||
def decide_response(state: dict, responses) -> str:
|
||||
intent_responses = responses.get(state['last_intent'], ["Przepraszam, nie rozumiem. Możesz to powtórzyć?"])
|
||||
return random.choice(intent_responses)
|
||||
class DialoguePolicy:
|
||||
def __init__(self, dst):
|
||||
self.dialogue_state = dst.state
|
||||
|
||||
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.')])
|
Loading…
Reference in New Issue
Block a user