本篇笔记所对应的视频 https://www.bilibili.com/video/BV1Q9XLYiEwD/
Mistral AI 最新推出的 Mistral Small 3.1 模型无疑是近期科技界的一大亮点。这款由法国 AI 实验室 Mistral AI 开发的开源多模态模型,以其卓越的性能和灵活性,为开发者、企业和研究人员带来了全新的可能性。凭借 24B 参数、对文本与图像的处理能力,以及在多个关键指标上的突破,Mistral Small 3.1 正成为 2025 年 AI 领域的一颗耀眼新星。
Mistral Small 3.1 是一款轻量级、高性能的 AI 模型,专为低延迟任务设计。相比前代 Mistral Small 3,3.1 版本在文本处理能力上显著提升,并新增了多模态功能,可同时处理文本和图像输入。其上下文窗口高达 128k 标记(token),推理速度达到 150 个标记每秒,效率令人惊叹。
这款模型的最大亮点在于其 开源性质,采用 Apache 2.0 许可证,用户可以免费下载、修改和部署。无论是个人开发者还是企业用户,都能根据需求进行定制。此外,Mistral Small 3.1 支持包括中文在内的多种语言,具备全球化的应用潜力。
Mistral Small 3.1 在多项基准测试中表现优异,特别是在 GPQA(Google Proof Question Answering) 测试中,超越了 Claude 3.5 Haiku、Gemma 3 和 GPT-4o-mini 等知名模型。在多语言任务中,其在欧洲和东亚语言理解上的表现也优于 GPT-4o Mini 和 Gemma 3。
更令人印象深刻的是,Mistral Small 3.1 的推理速度达到 150 个标记每秒,成为目前市场上最快的模型之一。这一优势使其在需要快速响应的场景中脱颖而出,例如虚拟助手和实时数据分析。
Mistral Small 3.1 的多功能性和高效性使其适用于多种场景,以下是几个典型应用:
自动化
通过 HTTP 请求,Mistral Small 3.1 可无缝集成到自动化流程中,例如 CRM(客户关系管理)、数据库管理和客户支持等领域。
图像分析
借助多模态能力,模型可生成图像描述或分析内容,适用于社交媒体图像自动标注、内容审核等任务。
学习与实验
开源代码为学生和 AI 初学者提供了一个理想平台,用户可以自由探索模型,深入理解 AI 技术。
Mistral Small 3.1 的推出降低了 AI 使用的门槛,其轻量级设计允许在本地计算机上运行,无需依赖云服务,这对于数据隐私和安全敏感的场景尤为重要。同时,快速响应能力和多语言支持使其在全球范围内具备广泛适用性。
Mistral AI 表示,Mistral Small 3.1 是其创新之路的一部分,未来还将推出更多增强推理能力的模型。这款模型不仅推动了 AI 技术的发展,也为用户提供了一个强大且灵活的工具,助力他们在 AI 领域实现更多突破。
Mistral Small 3.1 的问世标志着 AI 模型在性能、效率和可访问性上的重要进步。无论是开发者、企业还是研究人员,都能从中受益,探索 AI 的无限可能。如果你正在寻找一款高效、开源且多功能的 AI 模型,Mistral Small 3.1 无疑值得关注!
python -m venv .venv
source .venv/bin/activate
python -m pip install langflow
python -m langflow run
✅文言文翻译
九月甲午,晋侯秦伯围郑,以其无礼于晋,且贰于楚也。晋 军函陵,秦军汜南。
佚之狐言于郑伯曰:“国危矣!若使烛之武见秦君,师必 退。
”公从之。辞曰:“臣之壮也,犹不如人;今老矣,无能力也 已。”
公曰:“吾不能早用子,今急而求子,是寡人之过也。然郑 亡,子亦有不利焉!”许之。
✅中文能力
识别以下句子中的讽刺或反语,并解释其真实含义:
a. "你真是个天才,连这么简单的问题都解决不了。"
b. "这报告写得真好,我看了三遍都没看懂。"
c. "你的解释非常清楚,把简单的问题变得更加复杂了。"
d. "你的房间整理得太干净了,连路都走不出来。"
e. "他真是个好同事,总是把自己的工作推给别人做。"
✅言外之意理解
解释以下对话中的真实意图:
A: "这周末一起去看电影吧?"
B: "我这周末要准备下周的报告。"
A: "你觉得我的新发型怎么样?"
B: "颜色挺特别的。"
A: "这份工作需要加班,你能接受吗?"
B: "我家里有两个小孩要照顾。"
四个数的和是21,这四个数两两相乘得到的六个积分别是15、18、21、30、35和42。
请求出这四个数分别是多少。
✅这三个数是3、5、6、7
一个动物园里有水牛、鸵鸟和蛇,一共有75只动物。
水牛、鸵鸟和蛇的腿共有176条,水牛角和鸵鸟头与蛇头加起来一共98个。
求有多少头水牛、多少只鸵鸟和多少条蛇?
✅23头牛、42只鸵鸟和10条蛇
# Create a new virtual environment
python -m venv mistral_env
source mistral_env/bin/activate
# Install vLLM nightly build
pip install vllm --pre --extra-index-url --upgrade
python -c "import mistral_common; print(mistral_common.__version__)"
# 运行
c
# 调用
import requests
import json
from datetime import datetime
def query_model(prompt, system_prompt=None, temperature=0.15):
"""
Query the deployed Mistral model.
Args:
prompt (str): The user prompt to send to the model
system_prompt (str, optional): System prompt to guide model behavior
temperature (float, optional): Sampling temperature (default: 0.15)
Returns:
dict: The model's response
"""
# Current date for system prompt
today = datetime.now().strftime("%Y-%m-%d")
yesterday = (datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
# Default system prompt if none provided
if system_prompt is None:
system_prompt = f"""You are Mistral Small 3.1, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.
You power an AI assistant called Le Chat.
Your knowledge base was last updated on 2023-10-01.
The current date is {today}.
When you're not sure about some information, you say that you don't have the information and don't make up anything.
If the user's question is not clear, ambiguous, or does not provide enough context for you to accurately answer the question, you do not try to answer it right away and you rather ask the user to clarify their request (e.g. "What are some good restaurants around me?" => "Where are you?" or "When is the next flight to Tokyo" => "Where do you travel from?").
You are always very attentive to dates, in particular you try to resolve dates (e.g. "yesterday" is {yesterday}) and when asked about information at specific dates, you discard information that is at another date.
You follow these instructions in all languages, and always respond to the user in the language they use or request.
Next sections describe the capabilities that you have.
# WEB BROWSING INSTRUCTIONS
You cannot perform any web search or access internet to open URLs, links etc. If it seems like the user is expecting you to do so, you clarify the situation and ask the user to copy paste the text directly in the chat.
# MULTI-MODAL INSTRUCTIONS
You have the ability to read images, but you cannot generate images. You also cannot transcribe audio files or videos.
You cannot read nor transcribe audio files or videos."""
# API endpoint (adjust if your server is on a different host/port)
url = ""
# Prepare the request payload
payload = {
"model": "mistralai/Mistral-Small-3.1-24B-Instruct-2503",
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt}
],
"temperature": temperature
}
# Send the request to the server
headers = {
"Content-Type": "application/json"
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
# Return the processed response
if response.status_code == 200:
return response.json()
else:
return {"error": f"Request failed with status {response.status_code}", "details": response.text}
# Example usage
if __name__ == "__main__":
user_prompt = "Explain how large language models work"
response = query_model(user_prompt)
# Extract and print the model's response
try:
model_response = response["choices"][0]["message"]["content"]
print("Model response:")
print(model_response)
except KeyError:
print("Unexpected response format:", response)
# vLLM
curl \\
-H "Content-Type: application/json" \\
-d '{
"model": "mistralai/Mistral-Small-3.1-24B-Instruct-2503",
"messages": [
{
"role": "system",
"content": "You are Mistral Small 3.1, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.\\nYou power an AI assistant called Le Chat.\\nYour knowledge base was last updated on 2023-10-01.\\nThe current date is 2025-03-18.\\n\\nWhen you'\\''re not sure about some information, you say that you don'\\''t have the information and don'\\''t make up anything.\\nIf the user'\\''s question is not clear, ambiguous, or does not provide enough context for you to accurately answer the question, you do not try to answer it right away and you rather ask the user to clarify their request (e.g. \\"What are some good restaurants around me?\\" => \\"Where are you?\\" or \\"When is the next flight to Tokyo\\" => \\"Where do you travel from?\\").\\nYou are always very attentive to dates, in particular you try to resolve dates (e.g. \\"yesterday\\" is 2025-03-17) and when asked about information at specific dates, you discard information that is at another date.\\nYou follow these instructions in all languages, and always respond to the user in the language they use or request.\\nNext sections describe the capabilities that you have.\\n\\n# WEB BROWSING INSTRUCTIONS\\n\\nYou cannot perform any web search or access internet to open URLs, links etc. If it seems like the user is expecting you to do so, you clarify the situation and ask the user to copy paste the text directly in the chat.\\n\\n# MULTI-MODAL INSTRUCTIONS\\n\\nYou have the ability to read images, but you cannot generate images. You also cannot transcribe audio files or videos.\\nYou cannot read nor transcribe audio files or videos."
},
{
"role": "user",
"content": "识别以下句子中的讽刺或反语,并解释其真实含义:你真是个天才,连这么简单的问题都解决不了。"
}
],
"temperature": 0.15,
"max_tokens": 400
}'
# 模型id
mistral-small-latest
# 测试
curl --location "" \\
--header 'Content-Type: application/json' \\
--header 'Accept: application/json' \\
--header "Authorization: Bearer key" \\
--data '{
"model": "mistral-small-latest",
"messages": [
{
"role": "user",
"content": "What is the best French cheese?"
}
]
}'
# 多模态
curl \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer key" \\
-d '{
"model": "mistral-small-latest",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What’s in this image?"
},
{
"type": "image_url",
"image_url": ""
}
]
}
],
"max_tokens": 300
}'
# ocr与格式化输出
curl \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer key" \\
-d '{
"model": "mistral-small-latest",
"messages": [
{
"role": "system",
"content": [
{"type": "text",
"text" : "Extract the text elements described by the user from the picture, and return the result formatted as a json in the following format : {name_of_element : [value]}"
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "From this restaurant bill, extract the bill number, item names and associated prices, and total price and return it as a string in a Json object"
},
{
"type": "image_url",
"image_url": ""
}
]
}
],
"response_format":
{
"type": "json_object"
}
}'