• Stars
    star
    198
  • Rank 196,854 (Top 4 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 17 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A machine-assisted human-moderation toolkit.

OSMod - The ConversationAI Moderator App

Deploying an OSMod instance

Configuration

The configuration is found in packages/config/index.js. It is pretty self explanatory. All settings can be overridden via environment variables.

Of particular note, the following have no sensible defaults, and must be set in the environment before anything will work.

  • DATABASE_NAME: The MySQL database name, e.g., 'os_moderator'.
  • DATABASE_USER: The MySQL database user, e.g., 'os_moderator'.
  • DATABASE_PASSWORD: The MySQL database password.

In a production setting, you'll also have to set the following:

  • MODERATOR_URL: URL (including protocol, host and port) that OSMOD will listen on.

System setup:

Install mysql, node (v10 or better), npm (v6 or better) and redis. Instructions for Ubuntu:

sudo apt install mysql-server nodejs npm redis
sudo apt install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
sudo npm install -g npm n
sudo n v10
hash -r

System setup -- Docker

If you want to run your moderator instances in one of the preconfigured docker containers, you'll need to install docker. E.g., to install on Ubuntu 18.04 using apt

sudo apt install docker.io

# Add docker group to your account so you can talk to the local docker server.
# You probably need to log out and back in for groups to take effect.
sudo usermod -a -G docker `whoami`

sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# check things work
docker version
docker-compose --version.

Install dependencies and run the server

Install all node dependencies and run initial typescript compile.

./bin/install

Setup local MySQL:

sudo mysql << EOF
CREATE DATABASE $DATABASE_NAME;
CREATE USER IF NOT EXISTS '$DATABASE_USER' IDENTIFIED BY '$DATABASE_PASSWORD';
GRANT ALL on $DATABASE_NAME.* to $DATABASE_USER;
EOF

sudo mysql $DATABASE_NAME < seed/initial-database.sql
cd packages/backend-api
npx sequelize db:migrate
cd -

# Add a service user that can talk to the Perspective API:
bin/osmod users:create --group moderator --name "PerspectiveAPI" \
  --moderator-type "perspective-api" --api-key $YOUR_PERSPECTIVE_API_KEY

# Run the server
bin/watch

Alternatively, run in a docker container

To run the service in a local docker container, run the following commands:

# Make sure any local instances of MySQL and Redis are not running
# E.g., on Ubuntu, stop the services
sudo systemctl stop mysql.service redis_6379.service redis-server.service

# Create docker images and launch the service
docker-compose -f deployments/local/docker-compose.yml up -d

The docker-compose scripts will initialise the database and create an API service user, so you don't need to do those steps manually.

To shut down the service and delete all your containers:

docker-compose -f deployments/local/docker-compose.yml down

And to see what the container is doing:

docker-compose -f deployments/local/docker-compose.yml logs

The osmod CLI

You can manage your OSMod system using the osmod commandline tool:

./bin/osmod <command> <options>

where command is one of

  • users:create Create new OS Moderator users
  • users:get-token Get a JWT token for a user specified by id or email
  • comments:rescore Rescore comment.
  • comments:send-to-scorer Send comments to Endpoint of user object to get scored.
  • comments:calculate-text-size Using node-canvas, calculate a single comment height at a given width.
  • comments:recalculate-text-sizes Using node-canvas, recalculate comment heights at a given width.
  • comments:recalculate-top-scores Recalculate comment top scores.
  • comments:flag Flag comments.
  • comments:delete Delete all comments from the database.
  • denormalize Re-run denormalize counts

Managing Users

If you are an administrator, you can create other administrators, general moderator users, and service users via the settings pages in the OSMod UI. Also, if there are no admin users, the UI will turn the first user to log in into an admin. But you can also create users via the commandline.

Create a human user:

./bin/osmod users:create --group general --name "Name" --email "$EMAIL_OF_USER"

Replace general with admin if you want to create an administrator.

To create a service user - i.e., one that can connect via the API but not via the UI:

./bin/osmod users:create --group service --name "Robot"

Service users will require a JWT token. You can get this via the UI, or via running the following command:

./bin/osmod users:get-token --id 4

Management commands

To run a local server on :8080 and front-end on :8000

./bin/watch

Lint

./bin/lint

optionally you can run lint-fix to attempt auto-fixing most lint errors

./bin/lint-fix

Storybook

To preview individual widgets and components used by the the OSMod UI:

./bin/storybook

The frontend unit tests also use storybook to generate a HTML snapshot of the resulting widgets.
It then compares this snapshot to a stored version, allowing you to review and approve any changes.

To update stories that need new snapshots, go to packages/frontend-web and run

npm run storybook:test -- -u

Development

The project uses lerna to help manage development the several npm packages that are in this repository. Lerna sym-links package dependencies within this repository. Lerna is also used to publish updates to all these packages at once.

Running tests

To run the tests, you'll need to tweak your enviornment:

# Some tests need admin privileges to clean out the database
export DATABASE_NAME=os_moderator_test
export DATABASE_USER=root

# Run all the tests
NODE_ENV=test bin/test

# or you can run individual tests:
cd packages/backend-api
NODE_ENV=test npm run test
NODE_ENV=test ../../node_modules/.bin/ts-mocha 'src/test/domain/comments/*.spec.js' --recursive --timeout 10000

The bin/test script uses lerna to first compile all the typescript to javascript, then runs all the tests.

Deleting and recreating the database schema can take a very long time, hence the long timeout above. You may need to increase this even further if your system is particularly slow.

If you want to run a test in the debugger, add the --inspect-brk flag to the mocha invocation, then connect using the chrome inspector (URL: chrome://inspect).

What a running service looks like

While there can be many ways to setup a service, in general a deployment will typically be a single VM instance running these services:

A MySQL database that holds all of the applications state (See the data model doc).

  • Frontend-Webserver service hosting the static ReactJS site. This sends messages to the Backend API service.
  • Backend API service responsible for querying the SQL database and sending data to the front-end service. This is also the endpoint that receives requests from the commenting platform it is supporting moderation of; and it sends requests back to the commenting platform with user actions (e.g. to reject or approve comments).
  • Backend Work Queue service responsible for managing concurrent queue of asynchronous work. TODO(ldixon): add reddis stuff?
  • Some number of assistant services responsible for automating tasks. Typically this is just calling ML services like the Perspective API

More Repositories

1

perspectiveapi

Perspective is an API that uses machine learning models to score the perceived impact a comment might have on a conversation. See https://developers.perspectiveapi.com for more information.
888
star
2

unintended-ml-bias-analysis

Jupyter Notebook
324
star
3

conversationai-models

A repository to house model building experiments and tools that are part of the Conversation AI effort.
Jupyter Notebook
138
star
4

perspective-viewership-extension

Tune is a Chrome extension that allows users set the "volume" of comment threads online by choosing what comments to read based on Toxicity scores provided by the Perspective API.
TypeScript
86
star
5

harassment-manager

Harassment Manager is a web application that aims to empower users to document and take action on abuse targeted at them on online platforms.
TypeScript
72
star
6

perspectiveapi-authorship-demo

Example code to illustrate how to build an authorship experience using the perspective API
TypeScript
66
star
7

wikidetox

Experiments to help discussion on Wikipedia talk pages
OpenEdge ABL
66
star
8

perspectiveapi-simple-server

A simple nodejs server to allow controlled access to the Perspective API
TypeScript
35
star
9

unhealthy-conversations

A corpus of comments tagged for multiple attributes of unhealthiness.
Jupyter Notebook
33
star
10

conversationai.github.io

Website for conversationai.github.io
HTML
29
star
11

perspective-hacks

JavaScript
28
star
12

perspectiveapi-js-client

A simple example JS/TS client library
TypeScript
20
star
13

conversationai-crowdsource

Project Gold ✨
TypeScript
11
star
14

conversationai-moderator-reddit

Moderator support for reddit
Python
7
star
15

firestore-perspective-toxicity

TypeScript
7
star
16

perspectiveapi-proxy

Example code for an authenticated proxy for requests to the Perspective API
TypeScript
6
star
17

conversationai-moderator-wordpress

Wordpress support for Moderator
PHP
4
star
18

conversationai-moderator-discourse

Discourse support for Moderator
Ruby
3
star
19

perspectiveapi-appsscript

A Google AppsScript project illustrating how to use Perspective in Google Sheets.
TypeScript
1
star