Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Fix interactive web (#4140)
Browse files Browse the repository at this point in the history
* fix interactive web

* remove comment

* add task test
  • Loading branch information
klshuster committed Nov 5, 2021
1 parent a8e28f2 commit 697054e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions parlai/scripts/interactive_web.py
Expand Up @@ -25,6 +25,8 @@
import json
import time

from parlai.agents.local_human.local_human import LocalHumanAgent

HOST_NAME = 'localhost'
PORT = 8080

Expand Down Expand Up @@ -266,14 +268,14 @@ def wait():
def interactive_web(opt):
global SHARED

opt['task'] = 'parlai.agents.local_human.local_human:LocalHumanAgent'
human_agent = LocalHumanAgent(opt)

# Create model and assign it to the specified task
agent = create_agent(opt, requireModelExists=True)
agent.opt.log()
SHARED['opt'] = agent.opt
SHARED['agent'] = agent
SHARED['world'] = create_task(SHARED.get('opt'), SHARED['agent'])
SHARED['world'] = create_task(SHARED.get('opt'), [human_agent, SHARED['agent']])

MyHandler.protocol_version = 'HTTP/1.0'
httpd = HTTPServer((opt['host'], opt['port']), MyHandler)
Expand Down
12 changes: 8 additions & 4 deletions tests/test_interactive.py
Expand Up @@ -85,18 +85,19 @@ def _run_test_repeat(self, tmpdir: str, fake_input: FakeInput):


class TestInteractiveWeb(unittest.TestCase):
def test_iweb(self):
def test_iweb(self, task: str = None):
import threading
import random
import requests
import json
import parlai.scripts.interactive_web as iweb

port = random.randint(30000, 40000)
kwargs = {'model': 'repeat_query', 'port': port}
if task:
kwargs['task'] = task
thread = threading.Thread(
target=iweb.InteractiveWeb.main,
kwargs={'model': 'repeat_query', 'port': port},
daemon=True,
target=iweb.InteractiveWeb.main, kwargs=kwargs, daemon=True
)
thread.start()
iweb.wait()
Expand All @@ -123,6 +124,9 @@ def test_iweb(self):

iweb.shutdown()

def test_iweb_task(self):
self.test_iweb(task='convai2')


class TestProfileInteractive(unittest.TestCase):
def test_profile_interactive(self):
Expand Down

0 comments on commit 697054e

Please sign in to comment.