mirror of
https://github.com/hanzoai/engine.git
synced 2026-11-20 14:17:52 +00:00
4.9 KiB
4.9 KiB
Mistral Small 3.1 Model: mistralai/Mistral-Small-3.1-24B-Instruct-2503
The Mistral Small 3.1 model is a strong multimodal (text+vision) model with 128k context length, function calling, and strong visual understanding.
Quick Start
hanzo run -m mistralai/Mistral-Small-3.1-24B-Instruct-2503 --isq 4 --image photo.jpg -i "Describe this image"
Input Formats
The Python and HTTP APIs support sending inputs as:
- Images: URL, path to a local file, or base64 encoded string (via
image_url)
The Rust SDK takes images from the image crate.
Tool calling with Mistral Small 3.1
The Mistral Small 3.1 model itself does not come with the correct JINJA chat template to enable tool calling. We provide a chat template for
tool calling with Mistral Small 3.1, and you can use it by specifying the jinja_explicit parameter in the various APIs. For example:
hanzo serve -p 1234 --isq 4 --jinja-explicit chat_templates/mistral_small_tool_call.jinja -m mistralai/Mistral-Small-3.1-24B-Instruct-2503
HTTP API
- Start the server
hanzo serve -m mistralai/Mistral-Small-3.1-24B-Instruct-2503 --isq 4 -p 1234
- Send a request
from openai import OpenAI
client = OpenAI(api_key="foobar", base_url="http://localhost:1234/v1/")
completion = client.chat.completions.create(
model="default",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://www.nhmagazine.com/content/uploads/2019/05/mtwashingtonFranconia-2-19-18-108-Edit-Edit.jpg"
},
},
{
"type": "text",
"text": "What is this?",
},
],
},
],
max_tokens=256,
)
print(completion.choices[0].message.content)
- You can find an example of encoding the image via base64 here.
- You can find an example of loading an image locally here.
Python SDK
You can find this example here.
from hanzo import Runner, Which, ChatCompletionRequest, MultimodalArchitecture
runner = Runner(
which=Which.MultimodalPlain(
model_id="mistralai/Mistral-Small-3.1-24B-Instruct-2503",
arch=MultimodalArchitecture.Mistral3,
),
in_situ_quant="4"
)
res = runner.send_chat_completion_request(
ChatCompletionRequest(
model="default",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://www.nhmagazine.com/content/uploads/2019/05/mtwashingtonFranconia-2-19-18-108-Edit-Edit.jpg"
},
},
{
"type": "text",
"text": "What is this?",
},
],
}
],
max_tokens=256,
)
)
print(res.choices[0].message.content)
print(res.usage)
- You can find an example of encoding the image via base64 here.
- You can find an example of loading an image locally here.
Rust SDK
You can find this example here.
use anyhow::Result;
use hanzo::{IsqType, TextMessageRole, MultimodalMessages, MultimodalModelBuilder};
#[tokio::main]
async fn main() -> Result<()> {
let model =
MultimodalModelBuilder::new("mistralai/Mistral-Small-3.1-24B-Instruct-2503")
.with_isq(IsqType::Q4K)
.with_logging()
.build()
.await?;
let bytes = match reqwest::blocking::get(
"https://www.nhmagazine.com/content/uploads/2019/05/mtwashingtonFranconia-2-19-18-108-Edit-Edit.jpg",
) {
Ok(http_resp) => http_resp.bytes()?.to_vec(),
Err(e) => anyhow::bail!(e),
};
let image = image::load_from_memory(&bytes)?;
let messages = MultimodalMessages::new().add_image_message(
TextMessageRole::User,
"What is depicted here? Please describe the scene in detail.",
vec![image],
);
let response = model.send_chat_request(messages).await?;
println!("{}", response.choices[0].message.content.as_ref().unwrap());
dbg!(
response.usage.avg_prompt_tok_per_sec,
response.usage.avg_compl_tok_per_sec
);
Ok(())
}