-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6e25ee
commit a2539e3
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters