什么是ollama
一个简明易用的本地大模型运行框架,像docker一样,让更多用户可以方便地在自己电脑上玩转大模型。
支持很多非常流行的LLM,https://ollama.ai/library?sort=popular

下载安装
macOS
Windows
即将推出!目前您可以通过 WSL2 在 Windows 上安装 Ollama。
Linux 和 WSL2
curl https://ollama.ai/install.sh | shdocker
官方Ollama Docker 镜像 ollama/ollama可在 Docker Hub 上获取。
快速开始
运行并与 Llama 2 聊天:
ollama run llama2模型库
ollama.ai/library上提供的一系列Ollama支持的开源模型。
以下是一些可以下载的开源模型示例:
Llama 2:
ollama run llama2Mistral:
ollama run mistralDolphin Phi:
ollama run dolphin-phiPhi-2:
ollama run phiNeural Chat:
ollama run neural-chatStarling:
ollama run starling-lmCode Llama:
ollama run codellamaLlama 2 Uncensored:
ollama run llama2-uncensoredLlama 2 13B:
ollama run llama2:13bLlama 2 70B:
ollama run llama2:70bOrca Mini:
ollama run orca-miniVicuna:
ollama run vicunaLLaVA:
ollama run llava
注意:您应该至少有 8 GB 可用内存来运行 7B 模型,16 GB 来运行 13B 模型,32 GB 来运行 33B 模型。
定制模型
从 GGUF 导入
Ollama 支持在 Modelfile 中导入 GGUF 模型:
创建一个名为
Modelfile的文件,其中用FROM指定要导入模型的本地文件路径FROM ./vicuna-33b.Q4_0.gguf在 Ollama 中创建模型
ollama create example -f Modelfile运行模型
ollama run example
从 PyTorch 或 Safetensors 导入
详细信息请参阅导入模型指南。
自定义提示
Ollama 库中的模型可以通过提示进行定制。例如,要定制llama2模型:
ollama pull llama2创建一个Modelfile:
FROM llama2
# 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.更多示例请参阅示例目录。有关使用模型文件的更多信息,请参阅模型文件文档。
CLI 参考
创建模型
ollama create用于从模型文件创建模型。
ollama create mymodel -f ./Modelfile拉一个模型
ollama pull llama2此命令还可用于更新本地模型。只有有差异才会被拉出。
删除模型
ollama rm llama2复制模型
ollama cp llama2 my-llama2多行输入
对于多行输入,您可以使用以下方式换行文本""":
>>> """Hello,
... world!
... """
I'm a basic program that prints the famous "Hello, world!" message to the console.多式联运模型
>>> What's in this image? /Users/jmorgan/Desktop/smile.png
The image features a yellow smiley face, which is likely the central focus of the picture.传入提示作为参数
$ ollama run llama2 "Summarize this file: $(cat README.md)"
Ollama is a lightweight, extensible framework for building and running language models on the local machine. It provides a simple API for creating, running, and managing models, as well as a library of pre-built models that can be easily used in a variety of applications.列出您计算机上的模型
ollama list启动Ollama
当您想要启动 ollama 但不需要桌面应用程序时使用ollama serve。
构建
安装cmake并执行go:
brew install cmake go然后生成依赖:
go generate ./...然后构建二进制文件:
go build .更详细的说明可以在开发者指南中找到。
运行本地的构建
接下来,启动服务器:
./ollama serve最后,在单独的 shell 中运行模型:
./ollama run llama2REST API
Ollama 有一套用于运行和管理模型的 REST API。
生成响应
curl http://localhost:11434/api/generate -d '{
"model": "llama2",
"prompt":"Why is the sky blue?"
}'与模型聊天
curl http://localhost:11434/api/chat -d '{
"model": "mistral",
"messages": [
{ "role": "user", "content": "why is the sky blue?" }
]
}'其他接口请参阅API 文档。
社区整合
Web和桌面程序
终端
数据库
包管理器
库
LangChain and LangChain.js with example
LangChainGo with example
移动端
扩展和插件
Discollama (Discord bot inside the Ollama discord channel)
Llama Coder (Copilot alternative using Ollama)