简介
Codestral 是 Mistral AI 的编码专用模型 —— 220 亿参数、32K 上下文、覆盖 Python / JavaScript / Bash / Fortran 等 80+ 语言。开源权重的 Codestral 22B 在科研和非商用场景免费;生产用最新 Codestral 通过 Mistral API 或 Le Chat 调。适合 Continue / Aider 本地补全、延迟敏感的代码生成。兼容 Ollama / vLLM / llama.cpp / Continue / Aider / LiteLLM。装机时间 5 分钟(ollama pull 或拿 API key)。
用 Ollama 本地跑 Codestral
# 拉模型
ollama pull codestral
# 聊天
ollama run codestral
# 当补全服务跑(端口 11434)
curl http://localhost:11434/api/generate -d '{
"model": "codestral",
"prompt": "Write a Rust function that returns the Nth Fibonacci number using memoization."
}'Continue 接 Codestral
// Continue 扩展的 config.json
{
"models": [
{
"title": "Codestral (local)",
"provider": "ollama",
"model": "codestral",
"apiBase": "http://localhost:11434"
}
],
"tabAutocompleteModel": {
"title": "Codestral Autocomplete",
"provider": "ollama",
"model": "codestral"
}
}Aider 接 Codestral
# 走 Mistral API(生产)
export MISTRAL_API_KEY=your-key
aider --model mistral/codestral-latest
# 或走本地 Ollama
aider --model ollama/codestral通过 LiteLLM
from litellm import completion
response = completion(
model="codestral/codestral-latest",
messages=[{"role": "user", "content": "Refactor this Python function to use list comprehensions"}],
api_key=os.environ["CODESTRAL_API_KEY"],
)Codestral 和通用 Mistral 模型对比
| 模型 | 专长 | 适合 |
|---|---|---|
| Mistral Small | 通用 | 聊天、摘要、RAG |
| Codestral | 编码专用 | Tab 补全、重构、代码问答 |
| Mixtral 8x7B | 专家混合 | 高吞吐推理 |
FAQ
Q: Codestral 免费吗? A: Codestral 22B 开源权重在 Mistral AI Non-Production License 下免费(科研、非商用)。生产/商用通过 Mistral 的付费 API(la-platforme.mistral.ai)调。
Q: Codestral 跟 Claude / GPT 在编码上比怎样? A: 代码专项 benchmark(HumanEval、MBPP)上 Codestral 跟 Claude 3.5 Sonnet 持平。综合推理+编码 Claude / GPT-4 仍领先。Codestral 的胜场是本地部署和低延迟。
Q: Codestral 能微调吗? A: 能。Mistral 给了 Codestral 的 LoRA 微调配方。开源权重版本可以用任何标准工具(axolotl / unsloth / trl)微调。Mistral 也提供托管微调 API。