Ollama
本文内容均由Ollama官方文档翻译,仅供个人学习,如有差异请以官网文档为准(https://ollama.com)ollama.cadn.net.cn
快速上手大型语言模型。ollama.cadn.net.cn
macOS
下载ollama.cadn.net.cn
Windows
下载ollama.cadn.net.cn
Linux
curl -fsSL https://ollama.com/install.sh | sh
手动安装说明ollama.cadn.net.cn
Docker
官方的 Ollama Docker 镜像 ollama/ollama 已在 Docker Hub 上提供。ollama.cadn.net.cn
库
快速入门
要运行并聊天使用 Llama 3.2:ollama.cadn.net.cn
ollama run llama3.2
模型库
Ollama 支持 ollama.com/library 上提供的模型列表ollama.cadn.net.cn
以下是一些可下载的示例模型:ollama.cadn.net.cn
| 模型 |
参数 |
大小 |
下载 |
| 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 3 Mini |
3.8B |
2.3GB |
ollama run phi3 |
| Gemma 2 |
2B |
1.6GB |
ollama run gemma2:2b |
| Gemma 2 |
9B |
5.5GB |
ollama run gemma2 |
| Gemma 2 |
27B |
16GB |
ollama run gemma2:27b |
| 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 无限制版 |
7B |
3.8GB |
ollama run llama2-uncensored |
| LLaVA |
7B |
4.5GB |
ollama run llava |
| Solar |
10.7B |
6.1GB |
ollama run solar |
[!NOTE]
运行7B模型至少需要8 GB的RAM,运行13B模型需要16 GB,运行33B模型则需要32 GB。ollama.cadn.net.cn
自定义模型
从 GGUF 导入
Ollama 支持在 Modelfile 中导入 GGUF 模型:ollama.cadn.net.cn
创建一个名为 Modelfile 的文件,其中包含一条 FROM 指令,用于指定要导入的模型的本地文件路径。ollama.cadn.net.cn
FROM ./vicuna-33b.Q4_0.gguf
在 Ollama 中创建模型ollama.cadn.net.cn
ollama create example -f Modelfile
运行模型ollama.cadn.net.cn
ollama run example
从 Safetensors 导入
请参阅指南,了解有关导入模型的更多信息。ollama.cadn.net.cn
自定义提示
来自 Ollama 库的模型可通过提示(prompt)进行自定义。例如,要自定义 llama3.2 模型:ollama.cadn.net.cn
ollama pull llama3.2
创建一个 Modelfile:ollama.cadn.net.cn
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.cadn.net.cn
ollama create mario -f ./Modelfile
ollama run mario
>>> hi
Hello! It's your friend Mario.
有关使用 Modelfile 的更多信息,请参阅 Modelfile 文档。ollama.cadn.net.cn
CLI 参考文档
创建模型
ollama create 用于根据 Modelfile 创建模型。ollama.cadn.net.cn
ollama create mymodel -f ./Modelfile
拉取模型
ollama pull llama3.2
此命令也可用于更新本地模型。仅会拉取差异部分。ollama.cadn.net.cn
删除模型
ollama rm llama3.2
复制模型
ollama cp llama3.2 my-model
对于多行输入,您可以使用 """ 包裹文本:ollama.cadn.net.cn
>>> """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.cadn.net.cn
将提示作为参数传递
ollama run llama3.2 "Summarize this file: $(cat README.md)"
输出: Ollama 是一个轻量级、可扩展的框架,用于在本地机器上构建和运行语言模型。它提供了一个简单的 API,用于创建、运行和管理模型,同时还提供了一个预构建模型库,可轻松应用于各种场景。ollama.cadn.net.cn
ollama show llama3.2
列出您计算机上的模型
ollama list
列出当前已加载的模型
ollama ps
停止当前正在运行的模型
ollama stop llama3.2
启动 Ollama
ollama serve 用于在不启动桌面应用程序的情况下启动 ollama。ollama.cadn.net.cn
构建
请参阅 开发者指南ollama.cadn.net.cn
运行本地构建
接下来,启动服务器:ollama.cadn.net.cn
./ollama serve
最后,在一个独立的终端中运行一个模型:ollama.cadn.net.cn
./ollama run llama3.2
REST API
Ollama 提供了用于运行和管理模型的 REST API。ollama.cadn.net.cn
生成响应
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 文档 以获取所有端点。ollama.cadn.net.cn
Web 和 桌面应用
云服务
终端
Apple Vision Pro
数据库
包管理器
库
移动版
扩展与插件
支持的后端
可观测性
- Lunary 是领先的开源大语言模型(LLM)可观测性平台。它提供了一系列企业级功能,包括实时分析、提示词模板管理、个人身份信息(PII)脱敏以及全面的智能体(Agent)追踪。
- OpenLIT 是一款原生支持 OpenTelemetry 的工具,用于通过追踪和指标监控 Ollama 应用程序及 GPU。
- HoneyHive 是一个面向 AI 代理的可观测性与评估平台。使用 HoneyHive 可评估代理性能、分析失败原因,并监控生产环境中的质量表现。
- Langfuse 是一个开源的 LLM(大语言模型)可观测性平台,使团队能够协作监控、评估和调试 AI 应用程序。
- MLflow Tracing 是一个开源的 LLM 观测工具,提供便捷的 API 用于记录和可视化追踪数据,便于调试和评估生成式 AI 应用。