Analyze Toxicity with Perspective API
Made by Jigsaw
Analyze the perceived impact a comment might have on a conversation using Perspective API.
How this extension works
Use this extension to get toxicity scores from Perspective API for comments written to a Cloud Firestore collection.
This extension runs Perspective API on the text field and collection you configure. The API uses machine learning models to score the perceived impact a comment might have on a conversation by evaluating that comment across a range of emotional concepts, called attributes. When you install this extension, you will specify the attributes you want to receive scores for. Perspective's main attribute is TOXICITY, defined as "a rude, disrespectful, or unreasonable comment that is likely to make you leave a discussion". See a list of all available attributes on our developer site. Scores are retrieved when a new document is added to your collection or an existing document is modified.
By default, you're granted quota for 1 query per second (QPS) to Perspective API. For additional QPS, fill out a quota increase request as needed.
Note: If you add or update documents at a rate higher than your allotted QPS, you may exceed quota and the extension will fail to score your documents.
Perspective API is no-cost for all amounts of quota. However, the extension uses Firebase and Google Cloud Platform services which may have associated charges, including:
- Cloud Firestore
- Cloud Functions
When you use Firebase Extensions, you're only charged for the underlying resources that you use. A paid-tier billing plan is only required if the extension uses a service that requires a paid-tier plan, for example calling to a Google Cloud API or making outbound network requests to non-Google services. All Firebase services offer a no-cost tier of usage. Learn more about Firebase billing.
What you can configure
- Cloud Functions location
- Perspective API Key
- Attributes to receive scores for
- Collection path
- Input field name
- Output field name
- doNotStore flag value
Type: Cloud Function
Description: Listens for new comments in your specified Cloud Firestore collection, runs toxicity analysis, then writes the results back to the same document.
Type: Cloud Function
Description: Listens for updates to comments in your specified Cloud Firestore collection, runs toxicity analysis, then writes the results back to the same document.
How to install this extension
Using the Firebase console
To install and manage extensions, you can use the Firebase console.Install using console
Using the Firebase CLI
To install and manage extensions, you can also use the Firebase CLI:
Step 1: Run the following npm command to install the CLI or update to the latest CLI version.
npm install -g firebase-toolsDoesn't work? Take a look at the Firebase CLI reference or change your npm permissions.
Step 2: Set up a new Firebase project directory or navigate to an existing one
Step 3: Add this extension to your extension manifest by running
firebase ext:install jigsaw/firestore-perspective-toxicity --local --project=projectId_or_alias
Step 4 (Optional): Test this extension locally with the Firebase Emulator Suite
Step 5: Deploy the extensions in your manifest to your project
firebase deploy --only extensions --project=projectId_or_alias