30 lines
676 B
TypeScript
30 lines
676 B
TypeScript
import {
|
|
HookEventType,
|
|
PluginContext,
|
|
PluginHandler,
|
|
PluginParameters,
|
|
} from '../types';
|
|
import { postQualifire } from './globals';
|
|
|
|
export const handler: PluginHandler = async (
|
|
context: PluginContext,
|
|
parameters: PluginParameters,
|
|
eventType: HookEventType
|
|
) => {
|
|
const evaluationBody: any = {
|
|
input: context.request.text,
|
|
content_moderation_check: true,
|
|
};
|
|
|
|
if (eventType === 'afterRequestHook') {
|
|
evaluationBody.output = context.response.text;
|
|
}
|
|
|
|
try {
|
|
return await postQualifire(evaluationBody, parameters?.credentials?.apiKey);
|
|
} catch (e: any) {
|
|
delete e.stack;
|
|
return { error: e, verdict: false, data: null };
|
|
}
|
|
};
|