LLM plugin providing access to Mistral models using the Mistral API
Project description
llm-mistral
LLM plugin providing access to Mistral models using the Mistral API
Installation
Install this plugin in the same environment as LLM:
llm install llm-mistral
Usage
First, obtain an API key for the Mistral API.
Configure the key using the llm keys set mistral command:
llm keys set mistral
<paste key here>
You can now access the Mistral hosted models. Run llm models for a list.
To run a prompt through mistral-tiny:
llm -m mistral-tiny 'A sassy name for a pet sasquatch'
To start an interactive chat session with mistral-small:
llm chat -m mistral-small
Chatting with mistral-small
Type 'exit' or 'quit' to exit
Type '!multi' to enter multiple lines, then '!end' to finish
> three proud names for a pet walrus
1. "Nanuq," the Inuit word for walrus, which symbolizes strength and resilience.
2. "Sir Tuskalot," a playful and regal name that highlights the walrus' distinctive tusks.
3. "Glacier," a name that reflects the walrus' icy Arctic habitat and majestic presence.
To use a system prompt with mistral-medium to explain some code:
cat example.py | llm -m mistral-medium -s 'explain this code'
Vision
The Pixtral models are capable of interpreting images. You can use those like this:
llm -m pixtral-large 'describe this image' \
-a https://static.simonwillison.net/static/2025/two-pelicans.jpg
Output:
This image features two pelicans in flight against a clear blue sky. Pelicans are large water birds known for their long beaks and distinctive throat pouches, which they use for catching fish. In this photo, the birds are flying close to each other, showcasing their expansive wings and characteristic beaks. The clear sky provides a stark contrast, highlighting the details of their feathers and the graceful curves of their wings. The image captures a moment of synchronicity and elegance in nature.
You can pass filenames instead of URLs.
Audio
The Voxtral models - voxtral-small and voxtral-mini - are capable of accepting audio input. This currently only works for URLs to MP3 files hosted online:
llm -m voxtral-small \
-a https://static.simonwillison.net/static/2024/pelican-joke-request.mp3
Output:
What do you call a pelican with no teeth? A gum-ican
Tools
To see a list of Mistral models that support tools (most of them) run:
llm models --tools -q mistral
Try one out like this:
llm -m mistral-medium -T llm_time 'What time is it?' --td
Schemas
Mistral models (with the exception of codestral-mamba) also support schemas:
llm -m mistral-small --schema 'name,bio:one sentence' 'invent a cool dog'
Output:
{
"name": "CyberHound",
"bio": "A futuristic dog with glowing cybernetic enhancements and the ability to hack into any system."
}
Model options
All three models accept the following options, using -o name value syntax:
-o temperature 0.7: The sampling temperature, between 0 and 1. Higher increases randomness, lower values are more focused and deterministic.-o top_p 0.1: 0.1 means consider only tokens in the top 10% probability mass. Use this or temperature but not both.-o max_tokens 20: Maximum number of tokens to generate in the completion.-o safe_mode 1: Turns on safe mode, which adds a system prompt to add guardrails to the model output.-o random_seed 123: Set an integer random seed to generate deterministic results.-o prefix 'Prefix here: Set a prefix that will be used for the start of the response. Try{to encourage JSON orGlaDOS:to encourage a roleplay from a specific character.
Available models
Run llm models for a full list of Mistral models. This plugin configures the following alias shortcuts:
mistral-tinyformistral/mistral-tinymistral-nemoformistral/open-mistral-nemomistral-small-2312formistral/mistral-small-2312mistral-small-2402formistral/mistral-small-2402mistral-small-2409formistral/mistral-small-2409mistral-small-2501formistral/mistral-small-2501magistral-small-2506formistral/magistral-small-2506magistral-smallformistral/magistral-small-latestmistral-smallformistral/mistral-small-latestmistral-medium-2312formistral/mistral-medium-2312mistral-medium-2505formistral/mistral-medium-2505magistral-medium-2506formistral/magistral-medium-2506magistral-mediumformistral/magistral-medium-latestmistral-mediumformistral/mistral-medium-latestmistral-largeformistral/mistral-large-latestcodestral-mambaformistral/codestral-mamba-latestcodestralformistral/codestral-latestministral-3bformistral/ministral-3b-latestministral-8bformistral/ministral-8b-latestpixtral-12bformistral/pixtral-12b-latestpixtral-largeformistral/pixtral-large-latestdevstral-smallformistral/devstral-small-latestvoxtral-miniformistral/voxtral-mini-2507voxtral-smallformistral/voxtral-small-2507
Refreshing the model list
Mistral sometimes release new models.
To make those models available to an existing installation of llm-mistral run this command:
llm mistral refresh
This will fetch and cache the latest list of available models. They should then become available in the output of the llm models command.
Embeddings
The Mistral Embeddings API can be used to generate 1,024 dimensional embeddings for any text.
To embed a single string:
llm embed -m mistral-embed -c 'this is text'
This will return a JSON array of 1,024 floating point numbers.
Mistral's Codestral Embed is an embedding model that specializes in code. LLM supports that in four different sizes:
llm embed -m mistral/codestral-embed-256 -c 'code...'
llm embed -m mistral/codestral-embed-512 -c 'code...'
llm embed -m mistral/codestral-embed-1024 -c 'code...'
llm embed -m mistral/codestral-embed-1536 -c 'code...'
llm embed -m mistral/codestral-embed-3072 -c 'code...'
The number is the size of the vector that will be returned.
You can also use codestral-embed which is an alias for the default size, codestral-embed-1536.
The [LLM documentation](https://llm.datasette.io/en/stable/embeddings/index.html) has more, including how to embed in bulk and store the results in a SQLite database.
See [LLM now provides tools for working with embeddings](https://simonwillison.net/2023/Sep/4/llm-embeddings/) and [Embeddings: What they are and why they matter](https://simonwillison.net/2023/Oct/23/embeddings/) for more about embeddings.
## Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
```bash
cd llm-mistral
python3 -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
llm install -e '.[test]'
To run the tests:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_mistral-0.15.tar.gz.
File metadata
- Download URL: llm_mistral-0.15.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcdb5c67fbf45f3531bdbb8b5143c890a519626b7a05ee27a539e8bf71a6c066
|
|
| MD5 |
2b8c71589bc59d4f2cd41d0db60e4d27
|
|
| BLAKE2b-256 |
da328bc79ef5ee6fab99fc96c80592c7c4519819964f21d79bfc8dadb7abd9f2
|
Provenance
The following attestation bundles were made for llm_mistral-0.15.tar.gz:
Publisher:
publish.yml on simonw/llm-mistral
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_mistral-0.15.tar.gz -
Subject digest:
dcdb5c67fbf45f3531bdbb8b5143c890a519626b7a05ee27a539e8bf71a6c066 - Sigstore transparency entry: 278563282
- Sigstore integration time:
-
Permalink:
simonw/llm-mistral@06261b284d839b4094f73c009be118d6e0135a9b -
Branch / Tag:
refs/tags/0.15 - Owner: https://github.com/simonw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06261b284d839b4094f73c009be118d6e0135a9b -
Trigger Event:
release
-
Statement type:
File details
Details for the file llm_mistral-0.15-py3-none-any.whl.
File metadata
- Download URL: llm_mistral-0.15-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dfd15db761c040da49fa1675fc2581be95f16ca7757601a8ca3a245896ba5b4
|
|
| MD5 |
06a8c30d20a3c59b6c144899b26b998c
|
|
| BLAKE2b-256 |
458e58c3b8bdf1539d8689c8dd5a181b7dbbb78a9d62d6aa0e8bc959d59d0a24
|
Provenance
The following attestation bundles were made for llm_mistral-0.15-py3-none-any.whl:
Publisher:
publish.yml on simonw/llm-mistral
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_mistral-0.15-py3-none-any.whl -
Subject digest:
3dfd15db761c040da49fa1675fc2581be95f16ca7757601a8ca3a245896ba5b4 - Sigstore transparency entry: 278563298
- Sigstore integration time:
-
Permalink:
simonw/llm-mistral@06261b284d839b4094f73c009be118d6e0135a9b -
Branch / Tag:
refs/tags/0.15 - Owner: https://github.com/simonw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06261b284d839b4094f73c009be118d6e0135a9b -
Trigger Event:
release
-
Statement type: