Skip to content

Commit

Permalink
feat: audio support added
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed May 6, 2024
1 parent f6e25ee commit a2539e3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/apis/audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { TranscriptionCreateParams } from "openai/resources/audio/transcriptions";
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";
import { TranslationCreateParams } from "openai/resources/audio/translations";
import { SpeechCreateParams } from "openai/resources/audio/speech";

export class Audio extends ApiResource {
transcriptions: transcriptions;
translations: translations;
speech: speech;

constructor(client: any) {
super(client);
this.transcriptions = new transcriptions(client);
this.translations = new translations(client);
this.speech = new speech(client);
}
}

export class transcriptions extends ApiResource{
async create(
_body: TranscriptionCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: TranscriptionCreateParams = _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 response = await OAIclient.audio.transcriptions.create(body, opts).withResponse();
return finalResponse(response);
}
}


export class translations extends ApiResource{
async create(
_body: TranslationCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: TranslationCreateParams = _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 response = await OAIclient.audio.translations.create(body, opts).withResponse();
return finalResponse(response);
}
}


export class speech extends ApiResource{
async create(
_body: SpeechCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: SpeechCreateParams = _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 response = await OAIclient.audio.speech.create(body, opts).withResponse();
return finalResponse(response);
}
}
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export { Models } from "./models";
export { Batches } from "./batches";
export { FineTuning } from "./fineTuning"
export { Moderations } from "./moderations"
export { Audio } from "./audio"
export { VectorStores } from "./vectorStores"
export { BetaChat } from "./betaChat"
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class Portkey extends ApiClient {
batches = new API.Batches(this);
fineTuning = new API.FineTuning(this);
moderations = new API.Moderations(this);
audio = new API.audio(this);
beta = {
assistants: new API.Assistants(this),
threads: new API.Threads(this),
Expand Down

0 comments on commit a2539e3

Please sign in to comment.