mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Allow passing api key into OpenAIWhisperParser (#7281)
This just allows the user to pass in an api_key directly into OpenAIWhisperParser. Very simple addition.
This commit is contained in:
parent
4e7d0c115b
commit
34a2755a54
@ -1,4 +1,4 @@
|
||||
from typing import Iterator
|
||||
from typing import Iterator, Optional
|
||||
|
||||
from langchain.document_loaders.base import BaseBlobParser
|
||||
from langchain.document_loaders.blob_loaders import Blob
|
||||
@ -9,6 +9,9 @@ class OpenAIWhisperParser(BaseBlobParser):
|
||||
"""Transcribe and parse audio files.
|
||||
Audio transcription is with OpenAI Whisper model."""
|
||||
|
||||
def __init__(self, api_key: Optional[str] = None):
|
||||
self.api_key = api_key
|
||||
|
||||
def lazy_parse(self, blob: Blob) -> Iterator[Document]:
|
||||
"""Lazily parse the blob."""
|
||||
|
||||
@ -28,6 +31,10 @@ class OpenAIWhisperParser(BaseBlobParser):
|
||||
"pydub package not found, please install it with " "`pip install pydub`"
|
||||
)
|
||||
|
||||
# Set the API key if provided
|
||||
if self.api_key:
|
||||
openai.api_key = self.api_key
|
||||
|
||||
# Audio file from disk
|
||||
audio = AudioSegment.from_file(blob.path)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user