Mistral is a platform for providing endpoints for Large Language models.

Authentication

Set your MISTRAL_API_KEY environment variable. Get your key from here.

export MISTRAL_API_KEY=***

Example

Use Mistral with your Agent:

import os

from phi.agent import Agent, RunResponse
from phi.model.mistral import MistralChat

mistral_api_key = os.getenv("MISTRAL_API_KEY")

agent = Agent(
    model=MistralChat(
        id="mistral-large-latest",
        api_key=mistral_api_key,
    ),
    markdown=True
)

# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story.")
# print(run.content)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story.")

Params

ParameterTypeDefaultDescription
idstr"mistral-large-latest"The ID of the model.
namestr"MistralChat"The name of the model.
providerstr"Mistral"The provider of the model.
temperatureOptional[float]NoneControls randomness in output generation.
max_tokensOptional[int]NoneMaximum number of tokens to generate.
top_pOptional[float]NoneControls diversity of output generation.
random_seedOptional[int]NoneSeed for random number generation.
safe_modeboolFalseEnables content filtering.
safe_promptboolFalseApplies content filtering to prompts.
response_formatOptional[Union[Dict[str, Any], ChatCompletionResponse]]NoneSpecifies the desired response format.
request_paramsOptional[Dict[str, Any]]NoneAdditional request parameters.
api_keyOptional[str]NoneYour Mistral API key.
endpointOptional[str]NoneCustom API endpoint URL.
max_retriesOptional[int]NoneMaximum number of API call retries.
timeoutOptional[int]NoneTimeout for API calls in seconds.
client_paramsOptional[Dict[str, Any]]NoneAdditional client parameters.
mistral_clientOptional[Mistral]NoneCustom Mistral client instance.