Git Product home page Git Product logo

conversationai-moderator's Introduction

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:

mysql -u root -p << EOF
CREATE DATABASE $DATABASE_NAME;
CREATE USER '$DATABASE_USER' IDENTIFIED BY '$DATABASE_PASSWORD';
GRANT ALL on $DATABASE_NAME.* to $DATABASE_USER;
EOF

mysql -u root -p $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"

# 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

The Perspective API proxy

OSMod can communicate to the Perspective API via a proxy server: the Perspective API proxy.

There is a preconfigured proxy server set up for general use. The URL of this proxy is [https://osmod-assistant.appspot.com/]. To access it, you'll need to get a suitable authentication token from the Perspective API team. In this case you need to set your service user's proxy URL to https://osmod-assistant.appspot.com/api/score-comment.

Alternatively, if you have been given direct access to the Perspecitve API, you can create a Perspective API key in a Google Cloud project and then run a local instance of the proxy as described in the Perspective API proxy documentation. E.g.:

export GOOGLE_CLOUD_API_KEY=<API Key>
export AUTH_WHITELIST=$GOOGLE_SCORE_AUTH
export ATTRIBUTE_REQUESTS
read -r -d '' ATTRIBUTE_REQUESTS << EOM
{
  "ATTACK_ON_AUTHOR": {},
  "ATTACK_ON_COMMENTER": {},
  "INCOHERENT": {},
  "INFLAMMATORY": {},
  "OBSCENE": {},
  "OFF_TOPIC": {},
  "SPAM": {} ,
  "UNSUBSTANTIAL": {},
  "LIKELY_TO_REJECT": {},
  "TOXICITY": {}
}
EOM

cd $PERSPECTIVEAPI_PROXY_LOCATION
yarn install
PORT=8081 yarn run watch

Then use http://localhost:8081/api/score-comment as the proxy URL when creating your service user.

TODO: Move GOOGLE_SCORE_AUTH and other configuration into the proxy service user's config and document here

conversationai-moderator's People

Contributors

rufushamade avatar ericagreene avatar aalempijevic avatar iislucas avatar tdreyno avatar waalsh avatar jde avatar sorensenjs avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.