56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
from service.dialog_state_monitor import DialogStateMonitor
|
|
from service.dialog_policy import DialogPolicy
|
|
from service.natural_languag_understanding import NaturalLanguageUnderstanding
|
|
from service.natural_language_generation import NaturalLanguageGeneration, parse_frame
|
|
from service.templates import templates
|
|
|
|
# initialize classes
|
|
nlu = NaturalLanguageUnderstanding(use_mocks=False) # NLU
|
|
monitor = DialogStateMonitor() # DSM
|
|
dialog_policy = DialogPolicy() # DP
|
|
language_generation = NaturalLanguageGeneration(templates) # NLG
|
|
|
|
def frame_to_dict(frame):
|
|
return {
|
|
"act": frame.act,
|
|
"slots": [{"name": slot.name, "value": slot.value} for slot in frame.slots],
|
|
"act_understood": frame.act_understood,
|
|
}
|
|
|
|
|
|
# Main loop
|
|
dial_num = 0
|
|
print("CTRL+C aby zakończyć program.")
|
|
while True:
|
|
monitor.reset()
|
|
|
|
print(f"\n==== Rozpoczynasz rozmowę nr {dial_num} ====\n")
|
|
user_input = input("Witamy w naszej pizza-przez-internet. W czym mogę pomóc?\n")
|
|
|
|
while True:
|
|
# NLU
|
|
frame = nlu.predict(user_input)
|
|
# print("Frame: ", frame)
|
|
|
|
# DSM
|
|
monitor.update(frame)
|
|
|
|
# DP
|
|
system_action = dialog_policy.predict(monitor)
|
|
system_action_dict = frame_to_dict(system_action) # Ensure system_action is a dictionary
|
|
# print("System action: ", system_action_dict)
|
|
|
|
# NLG
|
|
response = language_generation.generate(frame, system_action_dict)
|
|
print(response)
|
|
|
|
if system_action.act == "bye_and_thanks" or system_action.act == "bye":
|
|
monitor.print_order()
|
|
break
|
|
|
|
if frame.act == "bye":
|
|
print(monitor.print_order())
|
|
break
|
|
|
|
user_input = input(">\n")
|
|
dial_num += 1 |