This commit is contained in:
Chester Curme 2025-02-21 19:32:09 -05:00
parent 4588e06794
commit 69400b8704
2 changed files with 54 additions and 58 deletions

View File

@ -661,35 +661,34 @@ class AzureChatOpenAI(BaseChatOpenAI):
@property @property
def root_client(self) -> openai.AzureOpenAI: def root_client(self) -> openai.AzureOpenAI:
if self._root_client is not None: if self._root_client is None:
return self._root_client sync_specific = {"http_client": self.http_client}
sync_specific = {"http_client": self.http_client} self._root_client = openai.AzureOpenAI(
self._root_client = openai.AzureOpenAI(**self._client_params, **sync_specific) # type: ignore[call-overload] **self._client_params,
**sync_specific, # type: ignore[call-overload]
)
return self._root_client return self._root_client
@property @property
def root_async_client(self) -> openai.AsyncAzureOpenAI: def root_async_client(self) -> openai.AsyncAzureOpenAI:
if self._root_async_client is not None: if self._root_async_client is None:
return self._root_async_client async_specific = {"http_client": self.http_async_client}
async_specific = {"http_client": self.http_async_client} self._root_async_client = openai.AsyncAzureOpenAI(
self._root_async_client = openai.AsyncAzureOpenAI( **self._client_params,
**self._client_params, **async_specific, # type: ignore[call-overload]
**async_specific, # type: ignore[call-overload] )
)
return self._root_async_client return self._root_async_client
@property @property
def client(self) -> Any: def client(self) -> Any:
if self._client is not None: if self._client is None:
return self._client self._client = self.root_client.chat.completions
self._client = self.root_client.chat.completions
return self._client return self._client
@property @property
def async_client(self) -> Any: def async_client(self) -> Any:
if self._async_client is not None: if self._async_client is None:
return self._async_client self._async_client = self.root_async_client.chat.completions
self._async_client = self.root_async_client.chat.completions
return self._async_client return self._async_client
@property @property

View File

@ -591,18 +591,17 @@ class BaseChatOpenAI(BaseChatModel):
# Configure a custom httpx client. See the # Configure a custom httpx client. See the
# [httpx documentation](https://www.python-httpx.org/api/#client) for more # [httpx documentation](https://www.python-httpx.org/api/#client) for more
# details. # details.
if self._http_client is not None: if self._http_client is None:
return self._http_client if not self.openai_proxy:
if not self.openai_proxy: return None
return None try:
try: import httpx
import httpx except ImportError as e:
except ImportError as e: raise ImportError(
raise ImportError( "Could not import httpx python package. "
"Could not import httpx python package. " "Please install it with `pip install httpx`."
"Please install it with `pip install httpx`." ) from e
) from e self._http_client = httpx.Client(proxy=self.openai_proxy)
self._http_client = httpx.Client(proxy=self.openai_proxy)
return self._http_client return self._http_client
@property @property
@ -612,51 +611,49 @@ class BaseChatOpenAI(BaseChatModel):
Must specify http_client as well if you'd like a custom client for sync Must specify http_client as well if you'd like a custom client for sync
invocations. invocations.
""" """
if self._http_async_client is not None: if self._http_async_client is None:
return self._http_async_client if not self.openai_proxy:
if not self.openai_proxy: return None
return None try:
try: import httpx
import httpx except ImportError as e:
except ImportError as e: raise ImportError(
raise ImportError( "Could not import httpx python package. "
"Could not import httpx python package. " "Please install it with `pip install httpx`."
"Please install it with `pip install httpx`." ) from e
) from e self._http_async_client = httpx.AsyncClient(proxy=self.openai_proxy)
self._http_async_client = httpx.AsyncClient(proxy=self.openai_proxy)
return self._http_async_client return self._http_async_client
@property @property
def root_client(self) -> openai.OpenAI: def root_client(self) -> openai.OpenAI:
if self._root_client is not None: if self._root_client is None:
return self._root_client sync_specific = {"http_client": self.http_client}
sync_specific = {"http_client": self.http_client} self._root_client = openai.OpenAI(
self._root_client = openai.OpenAI(**self._client_params, **sync_specific) # type: ignore[arg-type] **self._client_params,
**sync_specific, # type: ignore[arg-type]
)
return self._root_client return self._root_client
@property @property
def root_async_client(self) -> openai.AsyncOpenAI: def root_async_client(self) -> openai.AsyncOpenAI:
if self._root_async_client is not None: if self._root_async_client is None:
return self._root_async_client async_specific = {"http_client": self.http_async_client}
async_specific = {"http_client": self.http_async_client} self._root_async_client = openai.AsyncOpenAI(
self._root_async_client = openai.AsyncOpenAI( **self._client_params,
**self._client_params, **async_specific, # type: ignore[arg-type]
**async_specific, # type: ignore[arg-type] )
)
return self._root_async_client return self._root_async_client
@property @property
def client(self) -> Any: def client(self) -> Any:
if self._client is not None: if self._client is None:
return self._client self._client = self.root_client.chat.completions
self._client = self.root_client.chat.completions
return self._client return self._client
@property @property
def async_client(self) -> Any: def async_client(self) -> Any:
if self._async_client is not None: if self._async_client is None:
return self._async_client self._async_client = self.root_async_client.chat.completions
self._async_client = self.root_async_client.chat.completions
return self._async_client return self._async_client
@property @property