type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create moderation
* Classifies if text is potentially harmful.
*/
export async function main(
auth: Openai,
body: {
input: string | string[];
model?: string | ("text-moderation-latest" | "text-moderation-stable");
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/moderations`);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 255 days ago
type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create moderation
* Classifies if text violates OpenAI's Content Policy
*/
export async function main(
auth: Openai,
body: {
input: string | string[];
model?: string | ("text-moderation-latest" | "text-moderation-stable");
[k: string]: unknown;
}
) {
const url = new URL(`https://api.openai.com/v1/moderations`);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 351 days ago