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

Multi-agent chat first pass #264

Merged
merged 4 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ yarn-debug.log*
yarn-error.log*

*/src/config.js
**/_generated/**
71 changes: 71 additions & 0 deletions crowdsourcing/dialogues/multi_party_chat/frontend/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

import React from "react";
import ReactDOM from "react-dom";
import "bootstrap-chat/styles.css";

import { ChatApp, ChatMessage, DefaultTaskDescription } from "bootstrap-chat";

function RenderChatMessage({ message, mephistoContext, appContext, idx }) {
const { agentId } = mephistoContext;
const { currentAgentNames } = appContext.taskContext;

return (
<div>
<ChatMessage
isSelf={message.id === agentId || message.id in currentAgentNames}
agentName={
message.id in currentAgentNames
? currentAgentNames[message.id]
: message.id
}
message={message.text}
taskData={message.task_data}
messageId={message.message_id}
/>
</div>
);
}

function MainApp() {
return (
<ChatApp
renderMessage={({ message, idx, mephistoContext, appContext }) => (
<RenderChatMessage
message={message}
mephistoContext={mephistoContext}
appContext={appContext}
idx={idx}
key={message.message_id + "-" + idx}
/>
)}
defaultAppSettings={{volume: 0}}
renderSidePane={({ appContext, mephistoContext: { taskConfig } }) => (
<DefaultTaskDescription
chatTitle={taskConfig.chat_title}
taskDescriptionHtml={taskConfig.task_description}
>
<b>You've been assigned: </b>
{appContext.taskContext?.persona?.name}
<p>
<b>Your Persona: </b>
{appContext.taskContext?.persona?.persona}
</p>
<b>You are in: </b>
{appContext.taskContext?.location?.name}
<p>
{appContext.taskContext?.location?.description}
</p>
</DefaultTaskDescription>
)}
/>
);
}

ReactDOM.render(<MainApp />, document.getElementById("app"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#@package _global_
mephisto:
blueprint:
world_file: ${task_dir}/worlds.py
task_description_file: ${task_dir}/task_description.html
onboarding_qualification: multi-party-chat-qualification
custom_source_dir: ${task_dir}/frontend
num_conversations: 1
task:
task_name: light-multi-party-chat
task_title: "Multi-Party Fantasy Chat"
task_description: >
In this task you will have a conversation with two other people
in a fantasy setting. You will all be given characters, and should
have a conversation about your assigned characters and the setting,
taking natural turns.
task_reward: 1.80
task_tags: "dynamic,chat,testing,fantasy,role-playing"
96 changes: 96 additions & 0 deletions crowdsourcing/dialogues/multi_party_chat/run_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/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.


import os
from mephisto.operations.operator import Operator
from mephisto.tools.scripts import load_db_and_process_config
from mephisto.abstractions.blueprints.parlai_chat.parlai_chat_blueprint import (
BLUEPRINT_TYPE,
SharedParlAITaskState,
)

from light.graph.builders.one_room_builder import OneRoomChatBuilder
from light.data_model.light_database import LIGHTDatabase
import hydra
from omegaconf import DictConfig
from dataclasses import dataclass, field
from typing import List, Any

TASK_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
LIGHT_DB_PATH = "~/ParlAI/data/LIGHT/merged.db"

hydra_defaults = [
{"mephisto/blueprint": BLUEPRINT_TYPE},
{"mephisto/architect": "local"},
{"mephisto/provider": "mock"},
{"conf": "multi_chat"},
]

from mephisto.operations.hydra_config import RunScriptConfig, register_script_config


@dataclass
class ScriptConfig(RunScriptConfig):
defaults: List[Any] = field(default_factory=lambda: hydra_defaults)
task_dir: str = TASK_DIRECTORY
num_turns: int = field(
default=6,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mention in the PR description that you end after 8 turns, should this be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - updated this locally and happened to not commit this file...

metadata={
"help": "Number of min turns per worker before a conversation is complete"
},
)
turn_timeout: int = field(
default=300,
metadata={
"help": "Maximum response time before kicking "
"a worker out, default 300 seconds"
},
)


register_script_config(name="scriptconfig", module=ScriptConfig)


@hydra.main(config_path="hydra_configs", config_name="scriptconfig")
def main(cfg: DictConfig) -> None:
db, cfg = load_db_and_process_config(cfg)
ldb = LIGHTDatabase(LIGHT_DB_PATH)

world_opt = {
"num_turns": cfg.num_turns,
"turn_timeout": cfg.turn_timeout,
"builder": OneRoomChatBuilder(
ldb=ldb,
opt={
"db_path": LIGHT_DB_PATH,
"model_path": os.path.expanduser("~/LIGHT/models/"),
"suggestion_type": "hybrid",
"hybridity_prob": 0.2,
},
),
}

custom_bundle_path = cfg.mephisto.blueprint.get("custom_source_bundle", None)
if custom_bundle_path is not None:
assert os.path.exists(custom_bundle_path), (
"Must build the custom bundle with `npm install; npm run dev` from within "
f"the {TASK_DIRECTORY}/webapp directory in order to demo a custom bundle "
)
world_opt["send_task_data"] = True

shared_state = SharedParlAITaskState(
world_opt=world_opt, onboarding_world_opt=world_opt
)

operator = Operator(db)

operator.validate_and_run_config(cfg.mephisto, shared_state)
operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)


if __name__ == "__main__":
main()
37 changes: 37 additions & 0 deletions crowdsourcing/dialogues/multi_party_chat/task_description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<h3>What is this task?</h3>
<p>
In this task you will have a conversation with two other people
in a fantasy setting. You will all be given characters, and should
have a conversation about your assigned characters and the setting,
taking natural turns.
</p>
<br />
<h3>What do I talk about?</h3>
<p>
Anything, so long as you remain in character in the medieval fantasy world.
You should try to learn about your partners, or talk about yourself, or
the location you have all been assigned to.
</p>
<br />
<h3>When does the task end?</h3>
<p>
The conversation ends when all characters have exceeded the minimum
number of turns (8). Please don't repeatedly spam messages to hit this
minimum, as this will exclude you from doing future chats.
</p>

<br />
<h3>What NOT to do:</h3>
<ul>
<li>Do not talk about the task itself, or about MTurk</li>
<li>Avoid racism, sexism, hate speech, and other forms of inappropriate conversation. </li>
<li>Avoid <b>real world</b> topics and locations, and instead remain in the medieval fantasy setting.</li>
<li>
Don't direct into conversations where you pretend to take actions
(like "here you go! *gives item*"), stick to strictly chat.
</li>
<li>
Don't idle for too long or you will be disconnected from the chat
and unable to submit.
</li>
</ul>
Loading