facebookresearch / ParlAI

A framework for training and evaluating AI models on a variety of openly available dialogue datasets.
https://parl.ai
MIT License
10.49k stars 2.1k forks source link

Terminal Chat Service #2207

Closed domrigoglioso closed 4 years ago

domrigoglioso commented 4 years ago

Implement a chat service that runs in terminal as in #2079.

Runs a server locally that allows you to connect to it through terminal. When you send a message to it, it sends back the response from the agent. Uses the chat_service base implementations.

domrigoglioso commented 4 years ago

@klshuster

  1. How is the control flow going through classes? I.e. When the message comes from the messenger, which class receives it, and how is it assigned to an agent? When I receive a response from the agent how is it sent back?

    1. Assuming the basic control flow is observe message -> act -> send response to client -> wait for client input -> send client input -> observe message, how do each of these steps occur? (Could you point us to the functions which do that) I.e. Does observe_message get called by some server that runs the manager, and then act gets called by the manager for a specific agent?
  2. Any thoughts on implementing on how to implement this in a local server and client format? Which functions receive and send messages back and forth? (Between server and client, and between server and agent)

  3. Is there anywhere that has more documentation on how the Messenger service was implemented?

klshuster commented 4 years ago

Below, I will try my best to diagram exactly what happens, though I'd assume that as you have just abstracted all of this functionality into base classes, you will be pretty familiar with this flow. As an example, I will walk you through what happens with the Websockets` chat service implementation, which can be run locally. I think the following should answer most of your questions above @domrigoglioso.

The following is a somewhat high-level step-by-step view of what's going on for the Websockets implementation.

  1. First, one would run python ~/ParlAI/parlai/chat_service/services/websocket/run.py --config-path /path/to/config
  2. A player then connects to the port on which the socket handler is listening (in this case, via a UI) and sends a message.
    • Then, the Handler's on_message is called, which passes the message to the Manager
  3. Manager handles message, starts up worlds etc. via it's _manager_loop_fn
  4. Whenever an agent messages the page, the chat service manager _on_new_message is called, which puts message in Agent's data queue
  5. World calls agent.observe() (e.g. in Chatbot world), which calls manager's observe_message function
    • This has the socket write_message to its port, where the player observes it in the UI.

Tagging @young-k for visibility and @ideanl as he has direct experience with this.