52 lines
1.4 KiB
Python
52 lines
1.4 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
|
|
from convlab.dialog_agent import PipelineAgent
|
|
|
|
# initialize classes
|
|
nlu = NaturalLanguageUnderstanding() # NLU
|
|
monitor = DialogStateMonitor() # DSM
|
|
dialog_policy = DialogPolicy() # DP
|
|
language_generation = NaturalLanguageGeneration(templates) # NLG
|
|
|
|
agent = PipelineAgent(nlu=nlu, dst=monitor, policy=None, nlg=language_generation, name='sys')
|
|
resp = agent.response("Dzień dobry")
|
|
print(resp)
|
|
# 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("Możesz zacząć pisać.\n")
|
|
|
|
while True:
|
|
# NLU
|
|
frame = nlu.predict(user_input)
|
|
# print(frame)
|
|
|
|
# DSM
|
|
monitor.update(frame)
|
|
|
|
# DP
|
|
# print(dialog_policy.next_dialogue_act(monitor.read()).act)
|
|
|
|
# NLG
|
|
act, slots = parse_frame(frame)
|
|
response = language_generation.generate(act, slots)
|
|
print(response)
|
|
|
|
if frame.act == "bye":
|
|
break
|
|
|
|
user_input = input(">\n")
|
|
|
|
|
|
|
|
|
|
|
|
|