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.
|
|
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
# 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
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
File details
Details for the file mistral_common-1.4.4.tar.gz
.
File metadata
- Download URL: mistral_common-1.4.4.tar.gz
- Upload date:
- Size: 5.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 110e1b937aee99fdcf3cefc6b4e924e7e22ff445246090fe9215051245caa59c |
|
MD5 | f1e00415f63f838707d2e91f329f0a80 |
|
BLAKE2b-256 | b37c5391ddeb4720546314542e7ecf5c909bcb16c2044aafb7ff46b8a48f482b |
File details
Details for the file mistral_common-1.4.4-py3-none-any.whl
.
File metadata
- Download URL: mistral_common-1.4.4-py3-none-any.whl
- Upload date:
- Size: 6.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d657fcb5aad8e518617662c57e121919f9f93172c713cbc70cb7461811764f8a |
|
MD5 | 9e319a35f28f66c8a6268e72cf8e5d55 |
|
BLAKE2b-256 | d33e510708bfc40ec43f7f94ebf24ceb2a9831a7b3fd740867c8eb4148aab51d |