set global ssl context

This commit is contained in:
Chester Curme 2025-02-21 19:45:43 -05:00
parent 69400b8704
commit 24765e49fd

View File

@ -6,6 +6,7 @@ import base64
import json import json
import logging import logging
import os import os
import ssl
import sys import sys
import warnings import warnings
from io import BytesIO from io import BytesIO
@ -108,6 +109,8 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
global_ssl_context = ssl.create_default_context()
def _convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage: def _convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage:
"""Convert a dictionary to a LangChain message. """Convert a dictionary to a LangChain message.
@ -601,7 +604,9 @@ class BaseChatOpenAI(BaseChatModel):
"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, verify=global_ssl_context
)
return self._http_client return self._http_client
@property @property
@ -621,7 +626,9 @@ class BaseChatOpenAI(BaseChatModel):
"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, verify=global_ssl_context
)
return self._http_async_client return self._http_async_client
@property @property