Hi, I’m trying to do the content-filter and I get an error. Im using the code implemented by @ali.yeysides in the comment above. When I try to implemented I get:
createError.js:16 Uncaught (in promise) Error: Request failed with status code 400
Im fust calling the function with a basic string:
const contentFilter = async (prompt) => {
const toxic_threshold = -0.355;
const wrappedPrompt = `<|endoftext|>${prompt}\n--\nLabel:`;
const response = await openai.createCompletion("content-filter-alpha", {
prompt: wrappedPrompt,
temperature: 0,
max_tokens: 1,
top_p: 0,
logprobs: 10,
});
let output_label = response.data.choices[0].text;
if (output_label == "2") {
const logprobs = response.data.choices[0]["logprobs"]["top_logprobs"][0];
if (logprobs["2"] < toxic_threshold) {
const logprob_0 = logprobs["0"];
const logprob_1 = logprobs["1"];
if (logprob_0 && logprob_1) {
if (logprob_0 >= logprob_1) {
output_label = "0";
} else {
output_label = "1";
}
}
if (logprob_0 && !logprob_1) {
output_label = "0";
}
if (!logprob_0 && logprob_1){
output_label = "1";
}
}
}
if (!["0", "1", "2"].includes(output_label)) {
output_label = "2";
}
return output_label;
}
try {
contentFilter("Your content here")
} catch (error) {
console.log(error)
}