Skip to main content

LlamaIndex Llms Integration: Mistral

Installation

Install the required packages using the following commands:

%pip install llama-index-llms-mistralai
!pip install llama-index

Basic Usage

Initialize the MistralAI Model

To use the MistralAI model, create an instance and provide your API key:

from llama_index.llms.mistralai import MistralAI

llm = MistralAI(api_key="<replace-with-your-key>")

Generate Completions

To generate a text completion for a prompt, use the complete method:

resp = llm.complete("Paul Graham is ")
print(resp)

Chat with the Model

You can also chat with the model using a list of messages. Here’s an example:

from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="system", content="You are CEO of MistralAI."),
    ChatMessage(role="user", content="Tell me the story about La plateforme"),
]
resp = MistralAI().chat(messages)
print(resp)

Using Random Seed

To set a random seed for reproducibility, initialize the model with the random_seed parameter:

resp = MistralAI(random_seed=42).chat(messages)
print(resp)

Streaming Responses

Stream Completions

You can stream responses using the stream_complete method:

resp = llm.stream_complete("Paul Graham is ")
for r in resp:
    print(r.delta, end="")

Stream Chat Responses

To stream chat messages, use the following code:

messages = [
    ChatMessage(role="system", content="You are CEO of MistralAI."),
    ChatMessage(role="user", content="Tell me the story about La plateforme"),
]
resp = llm.stream_chat(messages)
for r in resp:
    print(r.delta, end="")

Configure Model

To use a specific model configuration, initialize the model with the desired model name:

llm = MistralAI(model="mistral-medium")
resp = llm.stream_complete("Paul Graham is ")
for r in resp:
    print(r.delta, end="")

Mistral Azure SDK Usage

To use the Mistral Azure SDK implementation, pass the Azure endpoint and API key. When these are provided, the client automatically uses the Mistral Azure SDK instead of the public Mistral endpoint.

from llama_index.llms.mistralai import MistralAI

llm = MistralAI(
    azure_endpoint="https://<your-resource-name>.openai.azure.com",
    azure_api_key="<replace-with-your-azure-key>",
    model="mistral-large-latest",
)

resp = llm.complete("Paul Graham is ")
print(resp)

Function Calling

You can call functions from the model by defining tools. Here’s an example:

from llama_index.llms.mistralai import MistralAI
from llama_index.core.tools import FunctionTool


def multiply(a: int, b: int) -> int:
    """Multiply two integers and return the result."""
    return a * b


def mystery(a: int, b: int) -> int:
    """Mystery function on two integers."""
    return a * b + a + b


mystery_tool = FunctionTool.from_defaults(fn=mystery)
multiply_tool = FunctionTool.from_defaults(fn=multiply)

llm = MistralAI(model="mistral-large-latest")
response = llm.predict_and_call(
    [mystery_tool, multiply_tool],
    user_msg="What happens if I run the mystery function on 5 and 7",
)
print(str(response))

LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/mistralai/

Metadata

Release files for llama-index-llms-mistralai 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-llms-mistralai 0.12.0
File Size Uploaded Provenance Actions
llama_index_llms_mistralai-0.12.0.tar.gz 10.0 kB Without provenance Details for llama_index_llms_mistralai-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-mistralai 0.12.0
File Interpreter ABI Platform Actions
llama_index_llms_mistralai-0.12.0-py3-none-any.whl Python 3 none any Details for llama_index_llms_mistralai-0.12.0-py3-none-any.whl

Total release size: 20.2 kB

Release files / llama_index_llms_mistralai-0.12.0.tar.gz

Download URL llama_index_llms_mistralai-0.12.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ff00677bd2724b4512256ae6059990e58224dc997ef14311c89369f9f7a0e736
BLAKE2b-256 checksum
How to use checksums
cc582156f738718420dba73eacbfe38e35f3b06faa17d1426d30140214d0f4ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_llms_mistralai-0.12.0-py3-none-any.whl

Download URL llama_index_llms_mistralai-0.12.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a15d3ab8551249e073243af5cfeb83422deccbcbeea7e37a322bdcc6918d3e18
BLAKE2b-256 checksum
How to use checksums
78e1eb1a20798f2591e5ccd3a096a98a2cd53e961d0c19a1f93368c195cbaabf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-llms-mistralai 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page