Skip to content

Commit 1a1c15c

Browse files
committed
Address copilot comments
1 parent db06b9f commit 1a1c15c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/checks/moderation.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,25 @@ export const ModerationContext = z.object({
7878

7979
export type ModerationContext = z.infer<typeof ModerationContext>;
8080

81+
/**
82+
* Check if an error is a 404 Not Found error from the OpenAI API.
83+
*
84+
* @param error The error to check
85+
* @returns True if the error is a 404 error
86+
*/
87+
function isNotFoundError(error: unknown): boolean {
88+
return !!(error && typeof error === 'object' && 'status' in error && error.status === 404);
89+
}
90+
8191
/**
8292
* Call the OpenAI moderation API.
8393
*
8494
* @param client The OpenAI client to use
8595
* @param data The text to analyze
8696
* @returns The moderation API response
8797
*/
88-
async function callModerationAPI(client: OpenAI, data: string) {
89-
return await client.moderations.create({
98+
function callModerationAPI(client: OpenAI, data: string) {
99+
return client.moderations.create({
90100
model: 'omni-moderation-latest',
91101
input: data,
92102
});
@@ -135,7 +145,7 @@ export const moderationCheck: CheckFn<ModerationContext, string, ModerationConfi
135145
} catch (error) {
136146
// Moderation endpoint doesn't exist on this provider (e.g., third-party)
137147
// Fall back to the OpenAI client
138-
if (error && typeof error === 'object' && 'status' in error && error.status === 404) {
148+
if (isNotFoundError(error)) {
139149
client = new OpenAI();
140150
resp = await callModerationAPI(client, data);
141151
} else {

0 commit comments

Comments
 (0)