Ollama
快速上手大型语言模型。
macOS
Windows
Linux
curl -fsSL https://ollama.com/install.sh | sh
手动安装说明
Docker
官方的 Ollama Docker 镜像 ollama/ollama
已在 Docker Hub 上提供。
库
社区
快速入门
要运行并与 Llama 3.2 对话:
ollama run llama3.2
模型库
Ollama 支持 ollama.com/library 上可用的模型列表。
以下是可以下载的一些示例模型:
模型名称 | 参数量 | 大小 | 下载命令 |
---|---|---|---|
Gemma 3 | 1B | 815MB | ollama run gemma3:1b |
Gemma 3 | 4B | 3.3GB | ollama run gemma3 |
Gemma 3 | 12B | 8.1GB | ollama run gemma3:12b |
Gemma 3 | 27B | 17GB | ollama run gemma3:27b |
QwQ | 32B | 20GB | ollama run qwq |
DeepSeek-R1 | 7B | 4.7GB | ollama run deepseek-r1 |
DeepSeek-R1 | 671B | 404GB | ollama run deepseek-r1:671b |
Llama 3.3 | 70B | 43GB | ollama run llama3.3 |
Llama 3.2 | 3B | 2.0GB | ollama run llama3.2 |
Llama 3.2 | 1B | 1.3GB | ollama run llama3.2:1b |
Llama 3.2 Vision | 11B | 7.9GB | ollama run llama3.2-vision |
Llama 3.2 Vision | 90B | 55GB | ollama run llama3.2-vision:90b |
Llama 3.1 | 8B | 4.7GB | ollama run llama3.1 |
Llama 3.1 | 405B | 231GB | ollama run llama3.1:405b |
Phi 4 | 14B | 9.1GB | ollama run phi4 |
Phi 4 Mini | 3.8B | 2.5GB | ollama run phi4-mini |
Mistral | 7B | 4.1GB | ollama run mistral |
Moondream 2 | 1.4B | 829MB | ollama run moondream |
Neural Chat | 7B | 4.1GB | ollama run neural-chat |
Starling | 7B | 4.1GB | ollama run starling-lm |
Code Llama | 7B | 3.8GB | ollama run codellama |
Llama 2 Uncensored | 7B | 3.8GB | ollama run llama2-uncensored |
LLaVA | 7B | 4.5GB | ollama run llava |
Granite-3.2 | 8B | 4.9GB | ollama run granite3.2 |
[!NOTE] 运行 7B 模型至少需要 8 GB 内存,运行 13B 模型需要 16 GB 内存,运行 33B 模型需要 32 GB 内存。
定制模型
从 GGUF 导入
Ollama 支持从 Modelfile 中导入 GGUF 模型:
-
创建一个名为
Modelfile
的文件,使用FROM
指令并提供要导入的模型的本地文件路径。FROM ./vicuna-33b.Q4_0.gguf
-
在 Ollama 中创建模型
ollama create example -f Modelfile
-
运行模型
ollama run example
从 Safetensors 导入
请参考指南了解更多关于导入模型的信息。
定制提示
来自 Ollama 库的模型可以通过提示进行定制。例如,定制 llama3.2
模型:
ollama pull llama3.2
创建一个 Modelfile
:
FROM llama3.2
# set the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1
# set the system message
SYSTEM """
You are Mario from Super Mario Bros. Answer as Mario, the assistant, only.
"""
接下来,创建并运行模型:
ollama create mario -f ./Modelfile
ollama run mario
>>> hi
Hello! It's your friend Mario.
了解更多关于使用 Modelfile 的信息,请查阅Modelfile 文档。
命令行界面参考
创建模型
使用 ollama create
命令可以从 Modelfile 创建一个模型。
ollama create mymodel -f ./Modelfile
提取模型
ollama pull llama3.2
这条命令同样可以用来更新本地模型。只会拉取差异部分。
删除模型
ollama rm llama3.2
复制模型
ollama cp llama3.2 my-model
多行输入
对于多行输入,您可以使用 """
将文本包裹起来:
>>> """Hello,
... world!
... """
I'm a basic program that prints the famous "Hello, world!" message to the console.
多模态模型
ollama run llava "What's in this image? /Users/jmorgan/Desktop/smile.png"
输出:图像展现了一个黄色的笑脸,这很可能是图片的中心焦点。
Pass the prompt as an argument
ollama run llama3.2 "Summarize this file: $(cat README.md)"
输出:Ollama 是一个轻量级、可扩展的框架,用于在本地计算机上构建和运行语言模型。它提供了创建、运行和管理模型的简单 API,以及一系列预构建模型的库,这些模型可以轻松地应用于各种场景。
显示模型信息
ollama show llama3.2
在您的计算机上列出模型
ollama list
列出当前已加载的模型
ollama ps
停止当前正在运行的模式
ollama stop llama3.2
开始 Ollama
使用 ollama serve
命令,可以在不运行桌面应用程序的情况下启动 ollama。
构建指南
请参阅开发者指南
运行本地构建
接下来,启动服务器:
./ollama serve
最后,在另一个独立的壳中,运行一个模型:
./ollama run llama3.2
REST API
Ollama 提供了一套 REST API,用于运行和管理模型。
生成响应
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt":"Why is the sky blue?"
}'
与模型对话
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [
{ "role": "user", "content": "why is the sky blue?" }
]
}'
查看API 文档了解所有端点。