Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions plugins/portkey/gibberish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PluginHandler,
PluginParameters,
} from '../types';
import { getText } from '../utils';
import { getCurrentContentPart } from '../utils';
import { PORTKEY_ENDPOINTS, fetchPortkey } from './globals';

export const handler: PluginHandler = async (
Expand All @@ -16,9 +16,17 @@ export const handler: PluginHandler = async (
let error = null;
let verdict = false;
let data: any = null;

let text = '';
try {
const text = getText(context, eventType);
const { content, textArray } = getCurrentContentPart(context, eventType);
if (!content) {
return {
error: { message: 'request or response json is empty' },
verdict: true,
data: null,
};
}
text = textArray.filter((text) => text).join('\n');
const not = parameters.not || false;

const response: any = await fetchPortkey(
Expand Down Expand Up @@ -47,7 +55,6 @@ export const handler: PluginHandler = async (
};
} catch (e) {
error = e as Error;
const text = getText(context, eventType);
data = {
explanation: `An error occurred while checking for gibberish: ${error.message}`,
not: parameters.not || false,
Expand Down
15 changes: 11 additions & 4 deletions plugins/portkey/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PluginHandler,
PluginParameters,
} from '../types';
import { getText } from '../utils';
import { getCurrentContentPart } from '../utils';
import { PORTKEY_ENDPOINTS, fetchPortkey } from './globals';

export const handler: PluginHandler = async (
Expand All @@ -16,9 +16,17 @@ export const handler: PluginHandler = async (
let error = null;
let verdict = false;
let data: any = null;

let text = '';
try {
const text = getText(context, eventType);
const { content, textArray } = getCurrentContentPart(context, eventType);
if (!content) {
return {
error: { message: 'request or response json is empty' },
verdict: true,
data: null,
};
}
text = textArray.filter((text) => text).join('\n');
const languages = parameters.language;
const not = parameters.not || false;

Expand Down Expand Up @@ -51,7 +59,6 @@ export const handler: PluginHandler = async (
};
} catch (e) {
error = e as Error;
const text = getText(context, eventType);
data = {
explanation: `An error occurred while checking language: ${error.message}`,
not: parameters.not || false,
Expand Down
15 changes: 11 additions & 4 deletions plugins/portkey/moderateContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PluginHandler,
PluginParameters,
} from '../types';
import { getText } from '../utils';
import { getCurrentContentPart } from '../utils';
import { PORTKEY_ENDPOINTS, fetchPortkey } from './globals';

export const handler: PluginHandler = async (
Expand All @@ -16,9 +16,17 @@ export const handler: PluginHandler = async (
let error = null;
let verdict = false;
let data: any = null;

let text = '';
try {
const text = getText(context, eventType);
const { content, textArray } = getCurrentContentPart(context, eventType);
if (!content) {
return {
error: { message: 'request or response json is empty' },
verdict: true,
data: null,
};
}
text = textArray.filter((text) => text).join('\n');
const categories = parameters.categories;
const not = parameters.not || false;

Expand Down Expand Up @@ -59,7 +67,6 @@ export const handler: PluginHandler = async (
};
} catch (e) {
error = e as Error;
const text = getText(context, eventType);
data = {
explanation: `An error occurred during content moderation: ${error.message}`,
not: parameters.not || false,
Expand Down