feat(llm): add Mistral as an LLM provider#562
Conversation
|
Hi 👋 Thank you for your contribution and interest in Dapr Agents 🎉 Can you pls run these commands to make the DCO build step happy: Also, if you use |
|
also, thank you so much for already opening the docs PR - that's amazing!! Also, we have pre-commit hooks for our repo to help avoid linter/build failures at CI time. There should be docs in the dev docs section of the repo with info on this :) It's under |
There was a problem hiding this comment.
Pull request overview
Adds a native Mistral LLM provider to dapr_agents.llm via the mistralai SDK, exposing a MistralChatClient and wiring it into the package exports so users can select Mistral as a first-class provider.
Changes:
- Introduces
MistralClientBase+MistralChatClientwith env-var model fallback (MISTRAL_MODEL). - Exports
MistralChatClientfromdapr_agents/llm/__init__.pyand adds themistralaidependency. - Adds initial unit tests for initialization and basic generate() behavior.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
dapr_agents/llm/mistral/client.py |
Adds the provider base client wrapper around the mistralai SDK client creation. |
dapr_agents/llm/mistral/chat.py |
Implements the Mistral chat client and hooks into shared request/response utilities. |
dapr_agents/llm/mistral/__init__.py |
Exposes Mistral client classes at the package level. |
dapr_agents/llm/__init__.py |
Re-exports MistralChatClient as part of the public LLM API surface. |
tests/llm/test_mistral.py |
Adds unit tests for env model fallback and a mocked generate() call. |
pyproject.toml |
Adds mistralai>=2.2.0 to runtime dependencies. |
uv.lock |
Locks mistralai (and transitive deps) into the resolved dependency set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aa82609 to
5a73f7e
Compare
|
Hi @sicoyle, thanks for the guidance! Pre-commit hooks are run, files are formatted, and all commits are now signed off. I've also addressed the Copilot review:
One question regarding Ready for another look! |
|
Edit: Scratch that, UI just didn't show |
| values["model"] = env_model | ||
| elif not values.get("model"): | ||
| values["model"] = "mistral-large-latest" | ||
| return values |
There was a problem hiding this comment.
Make sure this is well documented in dapr-docs but also that docstring reflect this for consumers of the MistralChatClient
There was a problem hiding this comment.
Done!
- Added class and method docstrings to
MistralChatClient. - Updated the
dapr/docsPR to document theMISTRAL_MODELfallback inline on the Core Concepts page.
| try: | ||
| # Mistral SDK v1.x | ||
| from mistralai import Mistral | ||
| except ImportError: | ||
| try: | ||
| # Mistral SDK v2.x | ||
| from mistralai.client import Mistral | ||
| except ImportError: | ||
| # Mistral SDK v0.x (Fallback) | ||
| from mistralai.client import MistralClient as Mistral |
There was a problem hiding this comment.
the pyproject toml file pins to v2.X.X. Can you pls rm the fallback and try/except setup here and just keep the import sitting alongside the other imports for logging, typing and such above? That way it's consistent too with the imports setup that the other LLM provider clients use :)
This is great! Full Mistral Prompty support can be done in a follow up PR :) |
|
@sicoyle I've made both requested changes. I'll tackle the full Mistral Prompty support in a follow-up PR after this merges. Thanks! |
sicoyle
left a comment
There was a problem hiding this comment.
This is great - thank you so much for your contribution! 🙌
Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com>
Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com>
Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com>
Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com>
Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com>
cf00e55 to
94084a0
Compare
|
Please resolve the conflicts and we can then merge |
Signed-off-by: Casper Nielsen <casper@diagrid.io>
|
I did not mean to re-request Copilot. Disregard whatever it may find. The PR is GTG 🚀 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| env_model = os.environ.get("MISTRAL_MODEL") | ||
| if env_model: | ||
| values["model"] = env_model | ||
| elif not values.get("model"): | ||
| values["model"] = "mistral-large-latest" |
| return LLMChatResponse( | ||
| id=resp.id, | ||
| model=resp.model, | ||
| results=[ | ||
| { |
| from mistralai.client import Mistral | ||
|
|
||
| from dapr_agents.llm.base import LLMClientBase | ||
| from dapr_agents.types.llm import MistralClientConfig |
| client = MistralChatClient() | ||
| assert client.model == "mistral-large-latest" |
| "wrapt>=1.14.0,<2.0.0", | ||
| "openinference-instrumentation>=0.1.0,<1.0.0", | ||
| "openinference-semantic-conventions>=0.1.0,<1.0.0", | ||
| "mistralai>=2.2.0", |
* feat(llm): add Mistral as an LLM provider Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com> * test(llm): add unit tests for Mistral provider Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com> * fix(llm): address PR review feedback and formatting for Mistral Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com> * docs(llm): clarify Mistral model fallback behavior in docstrings Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com> * refactor(llm): simplify Mistral imports and add config class Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com> --------- Signed-off-by: Rishabh Dewangan <107680241+Rishabh-git10@users.noreply.github.com> Signed-off-by: Casper Nielsen <casper@diagrid.io> Co-authored-by: Casper Nielsen <casper@diagrid.io>
Description
Adds
MistralChatClientto natively support Mistral as an LLM provider via themistralaiSDK. This allows users to configure custom endpoints and utilize multimodal features that are not supported by the generic Conversation API.Changes included:
MistralClientBaseandMistralChatClient.MISTRAL_MODELenvironment variable.dapr_agents/llm/__init__.py.mistralaito project dependencies (supports SDK v2 with v1 fallback).tests/llm/test_mistral.py.Issue reference
Closes #230
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list:
Note: We expect contributors to open a corresponding documentation PR in the dapr/docs repository. As the implementer, you are the best person to document your work! Implementation PRs will not be merged until the documentation PR is opened and ready for review.