Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(community): Add OpenAI Whisper options #7650

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 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,9 @@ 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, {
language: "es-CL",
});

const docs = await loader.load();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
*/
export class OpenAIWhisperAudio extends BufferLoader {
private readonly openAIClient: OpenAIClient;
private readonly transcriptionCreateParams?: Partial<OpenAIClient.Audio.TranscriptionCreateParams>;

Check failure on line 20 in libs/langchain-community/src/document_loaders/fs/openai_whisper_audio.ts

View workflow job for this annotation

GitHub Actions / Check linting

Expected blank line between class members

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

protected async parse(
Expand All @@ -38,6 +41,7 @@
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
Loading