Skip to main content

No project description provided

Project description

Mistral Common

What is it?

mistral-common is a set of tools to help you work with Mistral models.

Our first release contains tokenization. Our tokenizers go beyond the usual text <-> tokens, adding parsing of tools and structured conversation. We also release the validation and normalization code that is used in our API.

We are releasing three versions of our tokenizer powering different sets of models.

Open Model Tokenizer
Mistral 7B Instruct v0.1 v1
Mistral 7B Instruct v0.2 v1
Mistral 7B Instruct v0.3 v3
Mixtral 8x7B Instruct v0.1 v1
Mixtral 8x22B Instruct v0.1 v3
Mixtral 8x22B Instruct v0.3 v3
Codestral 22B v0.1 v3
Codestral Mamba 7B v0.1 v3
Mathstral 7B v0.1 v3
Nemo 12B 2407 v3 - Tekken
Large 123B 2407 v3
Endpoint Model Tokenizer
mistral-embed v1
open-mistral-7b v3
open-mixtral-8x7b v1
open-mixtral-8x22b v3
mistral-small-latest v2
mistral-large-latest v3
codestral-22b v3
open-codestral-mamba v3
open-mistral-nemo v3 - Tekken

Installation

pip

You can install mistral-common via pip:

pip install mistral-common

From Source

Alternatively, you can install from source directly. This repo uses poetry as a dependency and virtual environment manager.

You can install poetry with

pip install poetry

poetry will set up a virtual environment and install dependencies with the following command:

poetry install

Examples

Open In Colab
# Import needed packages:
from mistral_common.protocol.instruct.messages import (
    UserMessage,
)
from mistral_common.protocol.instruct.request import ChatCompletionRequest
from mistral_common.protocol.instruct.tool_calls import (
    Function,
    Tool,
)
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer

# Load Mistral tokenizer

model_name = "open-mixtral-8x22b"

tokenizer = MistralTokenizer.from_model(model_name)

# Tokenize a list of messages
tokenized = tokenizer.encode_chat_completion(
    ChatCompletionRequest(
        tools=[
            Tool(
                function=Function(
                    name="get_current_weather",
                    description="Get the current weather",
                    parameters={
                        "type": "object",
                        "properties": {
                            "location": {
                                "type": "string",
                                "description": "The city and state, e.g. San Francisco, CA",
                            },
                            "format": {
                                "type": "string",
                                "enum": ["celsius", "fahrenheit"],
                                "description": "The temperature unit to use. Infer this from the users location.",
                            },
                        },
                        "required": ["location", "format"],
                    },
                )
            )
        ],
        messages=[
            UserMessage(content="What's the weather like today in Paris"),
        ],
        model=model_name,
    )
)
tokens, text = tokenized.tokens, tokenized.text

# Count the number of tokens
print(len(tokens))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mistral_common-1.4.2.tar.gz (5.8 MB view details)

Uploaded Source

Built Distribution

mistral_common-1.4.2-py3-none-any.whl (6.0 MB view details)

Uploaded Python 3

File details

Details for the file mistral_common-1.4.2.tar.gz.

File metadata

  • Download URL: mistral_common-1.4.2.tar.gz
  • Upload date:
  • Size: 5.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for mistral_common-1.4.2.tar.gz
Algorithm Hash digest
SHA256 3b35cf7aa1f096b4b5b438e2be35801f453751bed37001936b43d2d3affcbae9
MD5 5b74512f2bd2fb19fdf22a30e9c03c5a
BLAKE2b-256 1d6f22fd56bcf289eb9bb895a4ad3232837c6b3f5a8e60b29f0137a35cef3a12

See more details on using hashes here.

File details

Details for the file mistral_common-1.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mistral_common-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 04f0feccc113f6c19f7fa12ead08f2425a82e60b78e8712a9da716c2a6eb1578
MD5 5ace00c44b23a8dac979785cf94427c4
BLAKE2b-256 794f9f896437666d9fcaf279180d0277c67242178ae4996161516ca4f93d24d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page