mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-29 06:23:20 +00:00
community[patch]: support OpenAI whisper base url (#17695)
**Description:** The base URL for OpenAI is retrieved from the environment variable "OPENAI_BASE_URL", whereas for langchain it is obtained from "OPENAI_API_BASE". By adding `base_url = os.environ.get("OPENAI_API_BASE")`, the OpenAI proxy can execute correctly. --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
44a3484503
commit
8e976545f3
@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from typing import Dict, Iterator, Optional, Tuple
|
||||
|
||||
@ -25,10 +26,17 @@ class OpenAIWhisperParser(BaseBlobParser):
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, api_key: Optional[str] = None, *, chunk_duration_threshold: float = 0.1
|
||||
self,
|
||||
api_key: Optional[str] = None,
|
||||
*,
|
||||
chunk_duration_threshold: float = 0.1,
|
||||
base_url: Optional[str] = None,
|
||||
):
|
||||
self.api_key = api_key
|
||||
self.chunk_duration_threshold = chunk_duration_threshold
|
||||
self.base_url = (
|
||||
base_url if base_url is not None else os.environ.get("OPENAI_API_BASE")
|
||||
)
|
||||
|
||||
def lazy_parse(self, blob: Blob) -> Iterator[Document]:
|
||||
"""Lazily parse the blob."""
|
||||
@ -51,11 +59,13 @@ class OpenAIWhisperParser(BaseBlobParser):
|
||||
|
||||
if is_openai_v1():
|
||||
# api_key optional, defaults to `os.environ['OPENAI_API_KEY']`
|
||||
client = openai.OpenAI(api_key=self.api_key)
|
||||
client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url)
|
||||
else:
|
||||
# Set the API key if provided
|
||||
if self.api_key:
|
||||
openai.api_key = self.api_key
|
||||
if self.base_url:
|
||||
openai.base_url = self.base_url
|
||||
|
||||
# Audio file from disk
|
||||
audio = AudioSegment.from_file(blob.path)
|
||||
|
Loading…
Reference in New Issue
Block a user