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:
Đỗ Quang Minh 2025-02-17 09:26:07 +07:00 committed by GitHub
parent 6874c9c1d0
commit cd198ac9ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -249,6 +249,7 @@ class OpenAIWhisperParser(BaseBlobParser):
Literal["json", "text", "srt", "verbose_json", "vtt"], None
] = None,
temperature: Union[float, None] = None,
model: str = "whisper-1",
):
self.api_key = api_key
self.chunk_duration_threshold = chunk_duration_threshold
@ -259,6 +260,7 @@ class OpenAIWhisperParser(BaseBlobParser):
self.prompt = prompt
self.response_format = response_format
self.temperature = temperature
self.model = model
@property
def _create_params(self) -> Dict[str, Any]:
@ -324,10 +326,10 @@ class OpenAIWhisperParser(BaseBlobParser):
try:
if is_openai_v1():
transcript = client.audio.transcriptions.create(
model="whisper-1", file=file_obj, **self._create_params
model=self.model, file=file_obj, **self._create_params
)
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
except Exception as e:
attempts += 1