Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 13 additions & 10 deletions src/workflows/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ const DEFAULT_THRESHOLDS = {
const DEFAULT_PROVIDER = "openai";

const HIVE_ENDPOINT = "https://api.thehive.ai/api/v2/task/sync";
const HIVE_SEXUAL_CATEGORIES = [
export const HIVE_SEXUAL_CATEGORIES = [
"general_nsfw",
"general_suggestive",
"yes_sexual_activity",
"sex_toys",
"nudity_female",
"nudity_male",
"yes_sex_toy",
"yes_female_nudity",
"yes_male_nudity",
];

const HIVE_VIOLENCE_CATEGORIES = [
export const HIVE_VIOLENCE_CATEGORIES = [
"gun_in_hand",
"gun_not_in_hand",
"knife_in_hand",
Expand All @@ -128,10 +127,8 @@ const HIVE_VIOLENCE_CATEGORIES = [
"hanging",
"noose",
"human_corpse",
"emaciated_body",
"self_harm",
"animal_abuse",
"fights",
"yes_emaciated_body",
"yes_self_harm",
"garm_death_injury_or_military_conflict",
];

Expand Down Expand Up @@ -325,6 +322,12 @@ function getHiveCategoryScores(
const scoreMap = Object.fromEntries(
classes.map(c => [c.class, c.score]),
);
const missingCategories = categoryNames.filter(category => !(category in scoreMap));
if (missingCategories.length > 0) {
console.warn(
`Hive response missing expected categories: ${missingCategories.join(", ")}`,
);
}
const scores = categoryNames.map(category => scoreMap[category] || 0);
return Math.max(...scores, 0);
}
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/moderation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";

import { HIVE_SEXUAL_CATEGORIES, HIVE_VIOLENCE_CATEGORIES } from "../../src/workflows/moderation";

describe("hive moderation categories", () => {
it("the HIVE_SEXUAL_CATEGORIES has not changed — If you change these, remember to check that these are accurate categories in Hive!", () => {
expect(HIVE_SEXUAL_CATEGORIES).toEqual([
"general_nsfw",
"yes_sexual_activity",
"yes_sex_toy",
"yes_female_nudity",
"yes_male_nudity",
]);
});

it("the HIVE_VIOLENCE_CATEGORIES has not changed — If you change these, remember to check that these are accurate categories in Hive!", () => {
expect(HIVE_VIOLENCE_CATEGORIES).toEqual([
"gun_in_hand",
"gun_not_in_hand",
"knife_in_hand",
"very_bloody",
"other_blood",
"hanging",
"noose",
"human_corpse",
"yes_emaciated_body",
"yes_self_harm",
"garm_death_injury_or_military_conflict",
]);
});
});