From f6e25eee43f523a9a7f286220cd22bf6c6e3af0f Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Mon, 6 May 2024 17:03:21 +0530 Subject: [PATCH] feat: moderations support added --- src/apis/index.ts | 1 + src/apis/moderations.ts | 34 ++++++++++++++++++++++++++++++++++ src/client.ts | 1 + 3 files changed, 36 insertions(+) create mode 100644 src/apis/moderations.ts diff --git a/src/apis/index.ts b/src/apis/index.ts index 9363a5d..4bb9e98 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -12,5 +12,6 @@ export { MainFiles } from "./files"; export { Models } from "./models"; export { Batches } from "./batches"; export { FineTuning } from "./fineTuning" +export { Moderations } from "./moderations" export { VectorStores } from "./vectorStores" export { BetaChat } from "./betaChat" diff --git a/src/apis/moderations.ts b/src/apis/moderations.ts new file mode 100644 index 0000000..f147faf --- /dev/null +++ b/src/apis/moderations.ts @@ -0,0 +1,34 @@ +import { ModerationCreateParams } from "openai/resources"; +import { ApiClientInterface } from "../_types/generalTypes"; +import { ApiResource } from "../apiResource"; +import { RequestOptions } from "../baseClient"; +import { OPEN_AI_API_KEY } from "../constants"; +import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils"; +import { createHeaders } from "./createHeaders"; +import OpenAI from "openai"; + + +export class Moderations extends ApiResource{ + async create(_body: ModerationCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): Promise { + const body: ModerationCreateParams = _body; + if (params) { + const config = overrideConfig(this.client.config, params.config); + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params, config }), + }; + } + + const OAIclient = new OpenAI({ + apiKey: OPEN_AI_API_KEY, + baseURL: this.client.baseURL, + defaultHeaders: defaultHeadersBuilder(this.client), + }); + + const result = await OAIclient.moderations.create(body, opts).withResponse(); + return finalResponse(result); + } +} \ No newline at end of file diff --git a/src/client.ts b/src/client.ts index 1904233..25021d7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -71,6 +71,7 @@ export class Portkey extends ApiClient { feedback = new API.Feedback(this); batches = new API.Batches(this); fineTuning = new API.FineTuning(this); + moderations = new API.Moderations(this); beta = { assistants: new API.Assistants(this), threads: new API.Threads(this),