forked from WHGTyen/ControllableComplexityChatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_utils.py
More file actions
33 lines (28 loc) · 1.11 KB
/
demo_utils.py
File metadata and controls
33 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from parlai.core.agents import Agent
from parlai.core.opt import Opt
from parlai.utils.world_logging import WorldLogger
from parlai.agents.local_human.local_human import LocalHumanAgent
from parlai.core.worlds import create_task
def start_interaction(agent: Agent, opt: Opt):
"""
Starts interactive mode. Code adapted from parlai/scripts/interactive.py
"""
human_agent = LocalHumanAgent(opt)
world_logger = WorldLogger(opt)
world = create_task(opt, [human_agent, agent])
# Show some example dialogs:
while not world.epoch_done():
world.parley()
if world.epoch_done() or world.get_total_parleys() <= 0:
# chat was reset with [DONE], [EXIT] or EOF
if world_logger is not None:
world_logger.reset()
continue
if world_logger is not None:
world_logger.log(world)
if opt.get('display_examples'):
print("---")
print(world.display())
if world_logger is not None:
# dump world acts to file
world_logger.write(opt['outfile'], world, file_format=opt['save_format'])