@@ -78,15 +78,25 @@ export const ModerationContext = z.object({
7878
7979export 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