Patch release v1.4.2
Make sure to send user agent for downloading pictures that require a user agent. E.g.:
from mistral_common.protocol.instruct.messages import (
UserMessage,
TextChunk,
ImageURLChunk,
ImageChunk,
)
from PIL import Image
from mistral_common.protocol.instruct.request import ChatCompletionRequest
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
tokenizer = MistralTokenizer.from_model("pixtral")
url_dog = "https://picsum.photos/id/237/200/300"
url_mountain = "https://picsum.photos/seed/picsum/200/300"
url1 = "https://upload.wikimedia.org/wikipedia/commons/d/da/2015_Kaczka_krzy%C5%BCowka_w_wodzie_%28samiec%29.jpg"
url2 = "https://upload.wikimedia.org/wikipedia/commons/7/77/002_The_lion_king_Snyggve_in_the_Serengeti_National_Park_Photo_by_Giles_Laurent.jpg"
# tokenize image urls and text
tokenized = tokenizer.encode_chat_completion(
ChatCompletionRequest(
messages=[
UserMessage(
content=[
TextChunk(text="Can this animal"),
ImageURLChunk(image_url=url1),
TextChunk(text="live here?"),
ImageURLChunk(image_url=url2),
]
)
],
model="pixtral",
)
)
tokens, text, images = tokenized.tokens, tokenized.text, tokenized.images
# Count the number of tokens
print("# tokens", len(tokens))
print("# images", len(images))
What's Changed
- typo: Correct "recieved" to "received" in MistralRequestValidator by @CharlesCNorton in #21
- Add headers to download images by @ywang96 in #51
- [Tests] Fix expected value by @patrickvonplaten in #50
- 1.4.2 release by @patrickvonplaten in #53
New Contributors
- @CharlesCNorton made their first contribution in #21
- @ywang96 made their first contribution in #51
Full Changelog: v1.4.1...v1.4.2