Skip to content

Commit

Permalink
feat: moderations support added
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed May 6, 2024
1 parent 0dd8306 commit f6e25ee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
34 changes: 34 additions & 0 deletions src/apis/moderations.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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);
}
}
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f6e25ee

Please sign in to comment.