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,16 +661,17 @@ class AzureChatOpenAI(BaseChatOpenAI):
@property
def root_client(self) -> openai.AzureOpenAI:
if self._root_client is not None:
return self._root_client
if self._root_client is None:
sync_specific = {"http_client": self.http_client}
self._root_client = openai.AzureOpenAI(**self._client_params, **sync_specific) # type: ignore[call-overload]
self._root_client = openai.AzureOpenAI(
**self._client_params,
**sync_specific, # type: ignore[call-overload]
)
return self._root_client
@property
def root_async_client(self) -> openai.AsyncAzureOpenAI:
if self._root_async_client is not None:
return self._root_async_client
if self._root_async_client is None:
async_specific = {"http_client": self.http_async_client}
self._root_async_client = openai.AsyncAzureOpenAI(
**self._client_params,
@ -680,15 +681,13 @@ class AzureChatOpenAI(BaseChatOpenAI):
@property
def client(self) -> Any:
if self._client is not None:
return self._client
if self._client is None:
self._client = self.root_client.chat.completions
return self._client
@property
def async_client(self) -> Any:
if self._async_client is not None:
return self._async_client
if self._async_client is None:
self._async_client = self.root_async_client.chat.completions
return self._async_client

View File

@ -591,8 +591,7 @@ class BaseChatOpenAI(BaseChatModel):
# Configure a custom httpx client. See the
# [httpx documentation](https://www.python-httpx.org/api/#client) for more
# details.
if self._http_client is not None:
return self._http_client
if self._http_client is None:
if not self.openai_proxy:
return None
try:
@ -612,8 +611,7 @@ class BaseChatOpenAI(BaseChatModel):
Must specify http_client as well if you'd like a custom client for sync
invocations.
"""
if self._http_async_client is not None:
return self._http_async_client
if self._http_async_client is None:
if not self.openai_proxy:
return None
try:
@ -628,16 +626,17 @@ class BaseChatOpenAI(BaseChatModel):
@property
def root_client(self) -> openai.OpenAI:
if self._root_client is not None:
return self._root_client
if self._root_client is None:
sync_specific = {"http_client": self.http_client}
self._root_client = openai.OpenAI(**self._client_params, **sync_specific) # type: ignore[arg-type]
self._root_client = openai.OpenAI(
**self._client_params,
**sync_specific, # type: ignore[arg-type]
)
return self._root_client
@property
def root_async_client(self) -> openai.AsyncOpenAI:
if self._root_async_client is not None:
return self._root_async_client
if self._root_async_client is None:
async_specific = {"http_client": self.http_async_client}
self._root_async_client = openai.AsyncOpenAI(
**self._client_params,
@ -647,15 +646,13 @@ class BaseChatOpenAI(BaseChatModel):
@property
def client(self) -> Any:
if self._client is not None:
return self._client
if self._client is None:
self._client = self.root_client.chat.completions
return self._client
@property
def async_client(self) -> Any:
if self._async_client is not None:
return self._async_client
if self._async_client is None:
self._async_client = self.root_async_client.chat.completions
return self._async_client