mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 15:19:33 +00:00
community: add custom model for OpenAIWhisperParser (#29831)
Add `model` properties for OpenAIWhisperParser. Defaulted to `whisper-1` (previous value). Please help me update the docs and other related components of this repo.
This commit is contained in:
parent
6874c9c1d0
commit
cd198ac9ed
@ -249,6 +249,7 @@ class OpenAIWhisperParser(BaseBlobParser):
|
|||||||
Literal["json", "text", "srt", "verbose_json", "vtt"], None
|
Literal["json", "text", "srt", "verbose_json", "vtt"], None
|
||||||
] = None,
|
] = None,
|
||||||
temperature: Union[float, None] = None,
|
temperature: Union[float, None] = None,
|
||||||
|
model: str = "whisper-1",
|
||||||
):
|
):
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.chunk_duration_threshold = chunk_duration_threshold
|
self.chunk_duration_threshold = chunk_duration_threshold
|
||||||
@ -259,6 +260,7 @@ class OpenAIWhisperParser(BaseBlobParser):
|
|||||||
self.prompt = prompt
|
self.prompt = prompt
|
||||||
self.response_format = response_format
|
self.response_format = response_format
|
||||||
self.temperature = temperature
|
self.temperature = temperature
|
||||||
|
self.model = model
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _create_params(self) -> Dict[str, Any]:
|
def _create_params(self) -> Dict[str, Any]:
|
||||||
@ -324,10 +326,10 @@ class OpenAIWhisperParser(BaseBlobParser):
|
|||||||
try:
|
try:
|
||||||
if is_openai_v1():
|
if is_openai_v1():
|
||||||
transcript = client.audio.transcriptions.create(
|
transcript = client.audio.transcriptions.create(
|
||||||
model="whisper-1", file=file_obj, **self._create_params
|
model=self.model, file=file_obj, **self._create_params
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
transcript = openai.Audio.transcribe("whisper-1", file_obj) # type: ignore[attr-defined]
|
transcript = openai.Audio.transcribe(self.model, file_obj) # type: ignore[attr-defined]
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
attempts += 1
|
attempts += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user