From 0cfe1a881e60c2dda0244930194695793941c4ab Mon Sep 17 00:00:00 2001 From: Ali Beyram Date: Mon, 28 Apr 2025 22:45:35 -0700 Subject: [PATCH 1/5] passing base_url to support mistral models that are hosted somewhee else (e.g. Azure) --- pydantic_ai_slim/pydantic_ai/providers/mistral.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pydantic_ai_slim/pydantic_ai/providers/mistral.py b/pydantic_ai_slim/pydantic_ai/providers/mistral.py index e491ecf2e..d8aebb7be 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/mistral.py +++ b/pydantic_ai_slim/pydantic_ai/providers/mistral.py @@ -44,6 +44,7 @@ def __init__( *, api_key: str | None = None, mistral_client: Mistral | None = None, + base_url: str | None = None, http_client: AsyncHTTPClient | None = None, ) -> None: """Create a new Mistral provider. @@ -67,7 +68,7 @@ def __init__( 'to use the Mistral provider.' ) elif http_client is not None: - self._client = Mistral(api_key=api_key, async_client=http_client) + self._client = Mistral(api_key=api_key, async_client=http_client, server_url=base_url) else: http_client = cached_async_http_client(provider='mistral') - self._client = Mistral(api_key=api_key, async_client=http_client) + self._client = Mistral(api_key=api_key, async_client=http_client, server_url=base_url) From aec197799abca6196773842b3cff276ff776d7d0 Mon Sep 17 00:00:00 2001 From: Ali Beyram Date: Wed, 30 Apr 2025 19:23:06 -0700 Subject: [PATCH 2/5] add base_url to docstring and in assert --- pydantic_ai_slim/pydantic_ai/providers/mistral.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pydantic_ai_slim/pydantic_ai/providers/mistral.py b/pydantic_ai_slim/pydantic_ai/providers/mistral.py index d8aebb7be..7ed4041f8 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/mistral.py +++ b/pydantic_ai_slim/pydantic_ai/providers/mistral.py @@ -53,11 +53,13 @@ def __init__( api_key: The API key to use for authentication, if not provided, the `MISTRAL_API_KEY` environment variable will be used if available. mistral_client: An existing `Mistral` client to use, if provided, `api_key` and `http_client` must be `None`. + base_url: The base url for the Mistral requests. http_client: An existing async client to use for making HTTP requests. """ if mistral_client is not None: assert http_client is None, 'Cannot provide both `mistral_client` and `http_client`' assert api_key is None, 'Cannot provide both `mistral_client` and `api_key`' + assert base_url is None, 'Cannot provide both `mistral_client` and `base_url`' self._client = mistral_client else: api_key = api_key or os.environ.get('MISTRAL_API_KEY') From c3c22493db4c8340f2a6256bfe368dea72b503c9 Mon Sep 17 00:00:00 2001 From: Ali Beyram Date: Wed, 30 Apr 2025 19:31:06 -0700 Subject: [PATCH 3/5] remove space --- pydantic_ai_slim/pydantic_ai/providers/mistral.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydantic_ai_slim/pydantic_ai/providers/mistral.py b/pydantic_ai_slim/pydantic_ai/providers/mistral.py index 7ed4041f8..d4f7c0632 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/mistral.py +++ b/pydantic_ai_slim/pydantic_ai/providers/mistral.py @@ -53,7 +53,7 @@ def __init__( api_key: The API key to use for authentication, if not provided, the `MISTRAL_API_KEY` environment variable will be used if available. mistral_client: An existing `Mistral` client to use, if provided, `api_key` and `http_client` must be `None`. - base_url: The base url for the Mistral requests. + base_url: The base url for the Mistral requests. http_client: An existing async client to use for making HTTP requests. """ if mistral_client is not None: From d4cb9bcaabb049ea023b33b8d38c43c287a01ef9 Mon Sep 17 00:00:00 2001 From: Ali Beyram Date: Wed, 30 Apr 2025 19:41:29 -0700 Subject: [PATCH 4/5] added to documentation --- docs/models/mistral.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/models/mistral.md b/docs/models/mistral.md index d3847edc7..e4f1a413b 100644 --- a/docs/models/mistral.md +++ b/docs/models/mistral.md @@ -52,7 +52,7 @@ from pydantic_ai.models.mistral import MistralModel from pydantic_ai.providers.mistral import MistralProvider model = MistralModel( - 'mistral-large-latest', provider=MistralProvider(api_key='your-api-key') + 'mistral-large-latest', provider=MistralProvider(api_key='your-api-key', base_url="https://") ) agent = Agent(model) ... From d59ac9ab1e0be4a175df16f1daa80758ea55e733 Mon Sep 17 00:00:00 2001 From: Ali Beyram Date: Wed, 30 Apr 2025 19:44:14 -0700 Subject: [PATCH 5/5] single quotes --- docs/models/mistral.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/models/mistral.md b/docs/models/mistral.md index e4f1a413b..c720dc583 100644 --- a/docs/models/mistral.md +++ b/docs/models/mistral.md @@ -52,7 +52,7 @@ from pydantic_ai.models.mistral import MistralModel from pydantic_ai.providers.mistral import MistralProvider model = MistralModel( - 'mistral-large-latest', provider=MistralProvider(api_key='your-api-key', base_url="https://") + 'mistral-large-latest', provider=MistralProvider(api_key='your-api-key', base_url='https://') ) agent = Agent(model) ...