Skip to content

Commit

Permalink
mistral[patch]: set global ssl context (#30189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme authored Mar 9, 2025
1 parent df459d0 commit b209d46
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libs/partners/mistralai/langchain_mistralai/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import re
import ssl
import uuid
from operator import itemgetter
from typing import (
Expand All @@ -24,6 +25,7 @@
cast,
)

import certifi
import httpx
from httpx_sse import EventSource, aconnect_sse, connect_sse
from langchain_core.callbacks import (
Expand Down Expand Up @@ -87,6 +89,11 @@
TOOL_CALL_ID_PATTERN = re.compile(r"^[a-zA-Z0-9]{9}$")


# This SSL context is equivelent to the default `verify=True`.
# https://www.python-httpx.org/advanced/ssl/#configuring-client-instances
global_ssl_context = ssl.create_default_context(cafile=certifi.where())


def _create_retry_decorator(
llm: ChatMistralAI,
run_manager: Optional[
Expand Down Expand Up @@ -518,6 +525,7 @@ def validate_environment(self) -> Self:
"Authorization": f"Bearer {api_key_str}",
},
timeout=self.timeout,
verify=global_ssl_context,
)
# todo: handle retries and max_concurrency
if not self.async_client:
Expand All @@ -529,6 +537,7 @@ def validate_environment(self) -> Self:
"Authorization": f"Bearer {api_key_str}",
},
timeout=self.timeout,
verify=global_ssl_context,
)

if self.temperature is not None and not 0 <= self.temperature <= 1:
Expand Down

0 comments on commit b209d46

Please sign in to comment.