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 @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._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 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,
@ -680,15 +681,13 @@ class AzureChatOpenAI(BaseChatOpenAI):
@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

View File

@ -591,8 +591,7 @@ 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:
@ -612,8 +611,7 @@ 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:
@ -628,16 +626,17 @@ class BaseChatOpenAI(BaseChatModel):
@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._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 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,
@ -647,15 +646,13 @@ class BaseChatOpenAI(BaseChatModel):
@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