Mistral
Use Mistral models with Kern agents.
Mistral is a platform for providing endpoints for Large Language models. See their library of models here.
We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:
codestralmodel is good for code generation and editing.mistral-large-latestmodel is good for most use-cases.open-mistral-nemois a free model that is good for most use-cases.pixtral-12b-2409is a vision model that is good for OCR, transcribing documents, and image comparison. It is not always capable at tool calling.
Mistral has tier-based rate limits. See the docs for more information.
Authentication
Set your MISTRAL_API_KEY environment variable. Get your key from here.
1export MISTRAL_API_KEY=***1setx MISTRAL_API_KEY ***Example
Use Mistral with your Agent:
1import os23from kern.agent import Agent, RunOutput4from kern.models.mistral import MistralChat56mistral_api_key = os.getenv("MISTRAL_API_KEY")78agent = Agent(9 model=MistralChat(10 id="mistral-large-latest",11 api_key=mistral_api_key,12 ),13 markdown=True14)1516# Print the response in the terminal17agent.print_response("Share a 2 sentence horror story.")Note View more examples here.
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "mistral-large-latest" | The id of the Mistral model to use |
name | str | "Mistral" | The name of the model |
provider | str | "Mistral" | The provider of the model |
api_key | Optional[str] | None | The API key for Mistral (defaults to MISTRAL_API_KEY env var) |
base_url | str | "https://api.mistral.ai/v1" | The base URL for the Mistral API |
timeout | Optional[int] | None | Request timeout in seconds |
MistralChat is a subclass of the Model class and has access to the same params.