forked from facebookresearch/ParlAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.py
70 lines (50 loc) · 1.79 KB
/
remote.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Simple loop which sets up a remote connection. The paired agent can run this same loop
but with the '--remote-host' flag set. For example...
Agent 1:
python remote.py
Agent 2:
python remote.py --remote-host
Now humans connected to each agent can communicate over that thread.
If you want to use this to feed a dataset to a remote agent, set the '--task':
Agent 1:
python remote.py -t "babi:task1k:1"
If you would like to use a model instead, merely set the '--model' flag:
Either Agent:
python remote.py -m seq2seq
"""
from parlai.agents.remote_agent.remote_agent import RemoteAgentAgent
from parlai.agents.local_human.local_human import LocalHumanAgent
from parlai.core.params import ParlaiParser
from parlai.core.agents import create_agent
from parlai.utils.logging import logger
from parlai.core.worlds import DialogPartnerWorld, create_task
import random
def main():
random.seed(42)
# Get command line arguments
parser = ParlaiParser(True, True)
RemoteAgentAgent.add_cmdline_args(parser)
opt = parser.parse_args()
remote = RemoteAgentAgent(opt)
if opt.get('task'):
world = create_task(opt, [remote])
else:
if opt.get('model'):
local = create_agent(opt)
else:
local = LocalHumanAgent(opt)
# the remote-host goes **second**
agents = [local, remote] if not opt['remote_host'] else [remote, local]
world = DialogPartnerWorld(opt, agents)
# Talk to the remote agent
with world:
while True:
world.parley()
logger.info(world.display())
if __name__ == '__main__':
main()