Ollama 是一个开源的大型语言模型(LLM)平台,旨在让用户能够轻松地在本地运行、管理和与大型语言模型进行交互。
curl -fsSL https://ollama.com/install.sh | sh
官方 Ollama Docker 镜像 ollama/ollama
可在 Docker Hub 上获取。
To run and chat with Gemma 3:
ollama run gemma3
Ollama 支持 ollama.com/library 上提供的一系列模型。以下是一些可供下载的示例模型:
Model | Parameters | Size | Download |
---|---|---|---|
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 4 | 109B | 67GB | ollama run llama4:scout |
Llama 4 | 400B | 245GB | ollama run llama4:maverick |
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.3 | 8B | 4.9GB | ollama run granite3.3 |
[!NOTE]
您应该至少有 8 GB 的 RAM 来运行 7B 型号,16 GB 来运行 13B 型号,以及 32 GB 来运行 33B 型号。
Ollama 支持在 Modelfile 中导入 GGUF 模型:
Create a file named Modelfile
, with a FROM
instruction with the local filepath to the model you want to import.
FROM ./vicuna-33b.Q4_0.gguf
Create the model in Ollama
ollama create example -f Modelfile
Run the model
ollama run example
请参阅导入模型的指南以了解更多信息。
您可以使用提示自定义 Ollama 库中的模型。例如,要自定义 llama3.2
模型:
ollama pull llama3.2
Create a 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.
"""
Next, create and run the model:
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
For multiline input, you can wrap text with """
:
>>> """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"
输出:图像上有一张黄色的笑脸,这可能是图片的中心焦点。
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”。
See the developer guide
Next, start the server:
./ollama serve
Finally, in a separate shell, run a model:
./ollama run llama3.2
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?" }
]
}'