Mistral代码开源编程 开源模型

Mistral Codestral 2501

Mistral Codestral系列 · Mistral AI · 2024-05发布

开源支持本地部署国内可直连有免费额度长上下文代码专用

模型介绍

Mistral 开源的代码生成模型,支持 80+ 编程语言,256K 上下文可处理整个代码库,兼容 Fill-in-the-Middle 补全格式,适合接入 IDE。

模型基础信息

模型系列Mistral Codestral系列
开发机构Mistral AI
发布时间2024-05
参数规模22B
上下文窗口256K
模型类型文本(代码专用)
中文能力良好
使用方式网页体验 / API调用 / 本地部署

免费额度与收费政策

开源免费(非商业) API 计费

免费规则详情

MNPL 许可限制商业用途;API 按 token 计费。

收费标准简介

本地免费;API 约 $0.30 / 百万 token(以官方为准)。

模型能力介绍

✅ 核心优势

  • 80+ 语�
  • 256K 长上下文
  • FIM 补全格式
  • IDE 友好

⚠️ 短板与局限

  • 非商业许可限制
  • 偏代码场景
  • 中文注释一般

🎯 适用场景

  • 代码补全
  • 代码生成
  • IDE 插件
  • 代码库分析

模型使用教程

本章节整理 Mistral Codestral 的在线体验、API调用、本地部署全套入门教程,快速上手使用该模型。

  • 本地体验:ollama run mistral-codestral 或 Transformers / vLLM 加载。
  • 云端:HF 托管模型可在线体验。
ollama run mistral-codestral "用中文介绍一下Mistral Codestral"
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download Mistral AI/Mistral Codestral --local-dir ./mistral-codestral

或 ModelScope 国内直连下载。

from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('Mistral AI/Mistral Codestral')
tok = AutoTokenizer.from_pretrained('Mistral AI/Mistral Codestral')
code = tok.apply_chat_template([{'role':'user','content':'你好'}], tokenize=False)
print(model.generate(**tok(code, return_tensors='pt')))

Codestral 22B(MNPL)是 Mistral 的代码模型,FIM 补全格式适合 IDE 内联补全,需约 48GB 显存(量化后 24GB)。

  1. 安装 vLLM:

pip install vllm

  1. 启动服务:

vllm serve mistralai/Codestral-22B-v0.1 --port 8000

  1. 在 Continue / Tabby 中把模型填 Codestral-22B、base URL 指向 http://localhost:8000/v1

Tips:MNPL 许可不可商用;IDE 补全体验接近商业工具。

💡 使用小技巧

接入插件(Continue/Tabby 等)体验最佳。

❓ 常见问题 FAQ

Q1:Codestral 能商用吗?\nA1:MNPL 限制商业,需授权。

访问备注与注意事项