diff --git a/src/core/client/admin/routes/Configure/sections/Moderation/PerspectiveConfig.tsx b/src/core/client/admin/routes/Configure/sections/Moderation/PerspectiveConfig.tsx
index 0d3989dd1..3a3b250c7 100644
--- a/src/core/client/admin/routes/Configure/sections/Moderation/PerspectiveConfig.tsx
+++ b/src/core/client/admin/routes/Configure/sections/Moderation/PerspectiveConfig.tsx
@@ -5,6 +5,10 @@ import { Field } from "react-final-form";
import { formatPercentage, parsePercentage } from "coral-framework/lib/form";
+import {
+ TOXICITY_MODEL_DEFAULT,
+ TOXICITY_THRESHOLD_DEFAULT,
+} from "coral-common/constants";
import { ExternalLink } from "coral-framework/lib/i18n/components";
import {
composeValidators,
@@ -32,9 +36,6 @@ import APIKeyField from "./APIKeyField";
import styles from "./PerspectiveConfig.css";
-/* TODO: use a common constants for both client and server. */
-const TOXICITY_DEFAULT = 80;
-
interface Props {
disabled: boolean;
}
@@ -69,7 +70,7 @@ const PerspectiveConfig: FunctionComponent = ({ disabled }) => {
}>
- Spam Detection Filter
+ Toxic Comment Filter
= ({ disabled }) => {
This value can be set a percentage between 0 and 100. This number
represents the likelihood that a comment is toxic, according to
- Perspective API. Defaults to $default.
+ Perspective API. By default the threshold is set to $default.
= ({ disabled }) => {
autoCapitalize="off"
spellCheck={false}
adornment={%}
- placeholder={TOXICITY_DEFAULT.toString()}
+ placeholder={TOXICITY_THRESHOLD_DEFAULT.toString()}
textAlignCenter
/>
{meta.touched && (meta.error || meta.submitError) && (
@@ -126,6 +127,53 @@ const PerspectiveConfig: FunctionComponent = ({ disabled }) => {
+
+
+
+ Toxicity Model
+
+
+
+ }
+ $default={TOXICITY_MODEL_DEFAULT}
+ >
+
+ Choose your Perspective Model. The default is $default. You can find
+ out more about model choices here.
+
+
+
+ {({ input, meta }) => (
+ <>
+
+ {meta.touched && (meta.error || meta.submitError) && (
+
+ {meta.error || meta.submitError}
+
+ )}
+ >
+ )}
+
+
+
}>
@@ -309,6 +351,7 @@ improve the API over time
https://github.com/conversationai/perspectiveapi/blob/master/quickstart.md
@@ -477,6 +520,7 @@ in your Akismet account:
https://akismet.com/account/
diff --git a/src/core/client/admin/test/configure/__snapshots__/wordList.spec.tsx.snap b/src/core/client/admin/test/configure/__snapshots__/wordList.spec.tsx.snap
index 5fccbaaa0..bbd4b3748 100644
--- a/src/core/client/admin/test/configure/__snapshots__/wordList.spec.tsx.snap
+++ b/src/core/client/admin/test/configure/__snapshots__/wordList.spec.tsx.snap
@@ -141,6 +141,7 @@ and paste a comma separated list?
Learn how to convert your list
@@ -198,6 +199,7 @@ and paste a comma separated list?
Learn how to convert your list
diff --git a/src/core/client/admin/test/configure/moderation.spec.tsx b/src/core/client/admin/test/configure/moderation.spec.tsx
index fe7e1ed92..b0883acb6 100644
--- a/src/core/client/admin/test/configure/moderation.spec.tsx
+++ b/src/core/client/admin/test/configure/moderation.spec.tsx
@@ -150,6 +150,7 @@ it("change perspective settings", async () => {
enabled: true,
endpoint: "https://custom-endpoint.net",
key: "my api key",
+ model: null,
threshold: 0.1,
}
);
diff --git a/src/core/client/framework/lib/i18n/components/ExternalLink.tsx b/src/core/client/framework/lib/i18n/components/ExternalLink.tsx
index 21217c7ea..8996ed43a 100644
--- a/src/core/client/framework/lib/i18n/components/ExternalLink.tsx
+++ b/src/core/client/framework/lib/i18n/components/ExternalLink.tsx
@@ -6,7 +6,17 @@ const ExternalLink: FunctionComponent<{
href?: string;
children?: string;
}> = ({ href, children }) => (
-
+
{children}
);
diff --git a/src/core/client/framework/lib/i18n/components/__snapshots__/ExternalLink.spec.tsx.snap b/src/core/client/framework/lib/i18n/components/__snapshots__/ExternalLink.spec.tsx.snap
index a1e593820..49419993c 100644
--- a/src/core/client/framework/lib/i18n/components/__snapshots__/ExternalLink.spec.tsx.snap
+++ b/src/core/client/framework/lib/i18n/components/__snapshots__/ExternalLink.spec.tsx.snap
@@ -4,6 +4,7 @@ exports[`renders correctly 1`] = `
http://test.com
diff --git a/src/core/common/constants.ts b/src/core/common/constants.ts
index 31f829e06..4c6a48835 100644
--- a/src/core/common/constants.ts
+++ b/src/core/common/constants.ts
@@ -16,3 +16,14 @@ export const CLIENT_ID_PARAM = "clientID";
* token in connectionParams when authenticating a websocket connection.
*/
export const ACCESS_TOKEN_PARAM = "accessToken";
+
+/**
+ * TOXICITY_THRESHOLD_DEFAULT is the default value used when the threshold is
+ * not set.
+ */
+export const TOXICITY_THRESHOLD_DEFAULT = 80;
+
+/**
+ * TOXICITY_MODEL_DEFAULT is the default value used for the toxicity model.
+ */
+export const TOXICITY_MODEL_DEFAULT = "TOXICITY";
diff --git a/src/core/server/graph/tenant/schema/schema.graphql b/src/core/server/graph/tenant/schema/schema.graphql
index 4a347f5eb..087999c94 100644
--- a/src/core/server/graph/tenant/schema/schema.graphql
+++ b/src/core/server/graph/tenant/schema/schema.graphql
@@ -763,6 +763,11 @@ type PerspectiveExternalIntegration {
"""
threshold: Float
+ """
+ model is the Perspective model to use.
+ """
+ model: String
+
"""
When True, comments sent will not be stored by the Google Perspective API.
"""
@@ -2693,6 +2698,11 @@ input SettingsPerspectiveExternalIntegrationInput {
"""
key: String
+ """
+ model is the name of the Perspective model to use.
+ """
+ model: String
+
"""
The threshold that given a specific toxic comment score, the comment will
be marked by Coral as toxic.
diff --git a/src/core/server/services/comments/pipeline/phases/toxic.ts b/src/core/server/services/comments/pipeline/phases/toxic.ts
index c7ef915dd..97088275a 100644
--- a/src/core/server/services/comments/pipeline/phases/toxic.ts
+++ b/src/core/server/services/comments/pipeline/phases/toxic.ts
@@ -2,6 +2,10 @@ import { isNil } from "lodash";
import ms from "ms";
import fetch from "node-fetch";
+import {
+ TOXICITY_MODEL_DEFAULT,
+ TOXICITY_THRESHOLD_DEFAULT,
+} from "coral-common/constants";
import { Omit } from "coral-common/types";
import { ToxicCommentError } from "coral-server/errors";
import {
@@ -56,8 +60,7 @@ export const toxic: IntermediateModerationPhase = async ({
let threshold = integration.threshold;
if (isNil(threshold)) {
- // TODO: (wyattjoh) replace hardcoded default with config.
- threshold = 0.8;
+ threshold = TOXICITY_THRESHOLD_DEFAULT / 100;
log.trace(
{ threshold },
@@ -81,17 +84,17 @@ export const toxic: IntermediateModerationPhase = async ({
try {
logger.trace("checking comment toxicity");
- // TODO: (wyattjoh) support custom toxicity model.
- const model = "TOXICITY";
+ // Pull the custom model out.
+ const model = integration.model || TOXICITY_MODEL_DEFAULT;
// Call into the Toxic comment API.
const score = await getScore(
comment.body,
- model,
{
endpoint,
key: integration.key,
doNotStore,
+ model,
},
timeout
);
@@ -142,10 +145,10 @@ export const toxic: IntermediateModerationPhase = async ({
*/
async function getScore(
text: string,
- model: string,
{
key,
endpoint,
+ model,
doNotStore,
}: Required>,
timeout: number
diff --git a/src/locales/en-US/admin.ftl b/src/locales/en-US/admin.ftl
index ae0fd6f75..c0b1b7fd0 100644
--- a/src/locales/en-US/admin.ftl
+++ b/src/locales/en-US/admin.ftl
@@ -245,11 +245,14 @@ configure-moderation-perspective-filter = Toxic Comment Filter
configure-moderation-perspective-toxicityThreshold = Toxicity Threshold
configure-moderation-perspective-toxicityThresholdDescription =
This value can be set a percentage between 0 and 100. This number represents the likelihood that a
- comment is toxic, according to Perspective API. By default the treshold is set to { $default }.
+ comment is toxic, according to Perspective API. By default the threshold is set to { $default }.
+configure-moderation-perspective-toxicityModel = Toxicity Model
+configure-moderation-perspective-toxicityModelDescription =
+ Choose your Perspective Model. The default is { $default }. You can find out more about model choices here.
configure-moderation-perspective-allowStoreCommentData = Allow Google to Store Comment Data
configure-moderation-perspective-allowStoreCommentDataDescription =
Stored comments will be used for future research and community model building purposes to
- improve the API over time
+ improve the API over time.
configure-moderation-perspective-customEndpoint = Custom Endpoint
configure-moderation-perspective-defaultEndpoint =
By default the endpoint is set to { $default }. You may override this here.