Skip to content

Commit

Permalink
feat(community): Add OpenAI Whisper options (#7650)
Browse files Browse the repository at this point in the history
Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
  • Loading branch information
fneiraj and jacoblee93 authored Feb 6, 2025
1 parent ded94d5 commit 0eedecf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/src/document_loaders/openai_whisper_audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { OpenAIWhisperAudio } from "@langchain/community/document_loaders/fs/ope

const filePath = "./src/document_loaders/example_data/test.mp3";

const loader = new OpenAIWhisperAudio(filePath);
const loader = new OpenAIWhisperAudio(filePath, {
transcriptionCreateParams: {
language: "en",
},
});

const docs = await loader.load();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const MODEL_NAME = "whisper-1";
export class OpenAIWhisperAudio extends BufferLoader {
private readonly openAIClient: OpenAIClient;

private readonly transcriptionCreateParams?: Partial<OpenAIClient.Audio.TranscriptionCreateParams>;

constructor(
filePathOrBlob: string | Blob,
fields?: {
clientOptions?: ClientOptions;
transcriptionCreateParams?: Partial<OpenAIClient.Audio.TranscriptionCreateParams>;
}
) {
super(filePathOrBlob);
this.openAIClient = new OpenAIClient(fields?.clientOptions);
this.transcriptionCreateParams = fields?.transcriptionCreateParams ?? {};
}

protected async parse(
Expand All @@ -38,6 +42,7 @@ export class OpenAIWhisperAudio extends BufferLoader {
await this.openAIClient.audio.transcriptions.create({
file: await toFile(raw, fileName),
model: MODEL_NAME,
...this.transcriptionCreateParams,
});
const document = new Document({
pageContent: transcriptionResponse.text,
Expand Down

0 comments on commit 0eedecf

Please sign in to comment.