Spaces:
Paused
Paused
Download src/providers/language-model/openai/runModerationCheck.mts from jbilcke-hf/VideoChain-API: direct link, hf CLI and curl.
- Browser
- Download file 759 Bytes
-
https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/main/src/providers/language-model/openai/runModerationCheck.mts
- Command line
-
hf download hf://spaces/jbilcke-hf/VideoChain-API/src/providers/language-model/openai/runModerationCheck.mts
-
curl -L -o runModerationCheck.mts https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/main/src/providers/language-model/openai/runModerationCheck.mts
759 Bytes
| import { | |
| CreateModerationResponseResultsInnerCategories, | |
| CreateModerationResponseResultsInnerCategoryScores, | |
| } from "openai" | |
| import { openai } from "./openai.mts" | |
| export const runModerationCheck = async ( | |
| input = '' | |
| ): Promise<{ | |
| categories?: CreateModerationResponseResultsInnerCategories | |
| category_scores?: CreateModerationResponseResultsInnerCategoryScores | |
| flagged: boolean | |
| }> => { | |
| if (!input || !input.length) { | |
| console.log(`skipping moderation check as input length is too shot`) | |
| return { | |
| flagged: false, | |
| } | |
| } | |
| const response = await openai.createModeration({ input }) | |
| const { results } = response.data | |
| if (!results.length) { | |
| throw new Error(`failed to call the moderation endpoint`) | |
| } | |
| return results[0] | |
| } |