For some reason, certain images return a 500 error from the moderation api. There are no specific error messages returned, so I have no idea what might be causing it. My code is not the issue, as some images work fine. All of my images are less than 1MB and are jpegs that have been converted to base64.
I have attached one of the images I am receiving an error for. You can also cause the error by submitting a completely white image.
async function contentModeration(filePath: string): Promise<boolean> {
// Convert to base64 url and send off for moderation.
const base64Image = await readFile(filePath, { encoding: "base64" });
const url = `data:image/jpeg;base64,${base64Image}`;
let moderation;
try {
moderation = await openai.moderations.create({
model: 'omni-moderation-latest',
input: [
{
type: 'image_url',
image_url: {
url
}
}
]
});
} catch (e) {
console.error('OpenAI API failed!');
console.error(e);
return false;
}
if (moderation.results[0].flagged) {
console.log(moderation.results[0].categories);
return false;
}
return true;
}
