第一行: 敬始皇,敬我们逝去的Pandora-next
之前一直在关注AI领域这一方面的信息,AI算是一次革命,今天我推荐的是一条命令快速在本地运行大模型,目前在GitHub超过35.7K start
GitHub项目地址: Ollama
官网地址: ollama官方网站
在本地启动并运行大型语言模型。甚至可以使用你的安卓手机跑本地大模型
先说点废话
MACOS
Windows
即将推出!目前,不过可以通过 WSL2 在 Windows 上安装 Ollama。
Linux 和 WSL2
curl https://ollama.ai/install.sh | sh
docker
官方Ollama Docker 镜像 ollama/ollama
可在 Docker Hub 上获取。
Libraries
快速开始
运行并与Llama 2聊天:
ollama run llama2
模型库
Ollama 支持ollama.ai/library上提供的一系列开源模型
让我比较惊讶的是竟然有qwen(千问)
注意:您应该至少有 8 GB 可用 RAM 来运行 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 serve
当您想要启动 ollama 而不运行桌面应用程序时使用。
构建
安装cmake
并go
:
brew install cmake go
然后生成依赖:
go generate ./...
然后构建二进制文件:
go build .
运行本地构建
接下来,启动服务器:
./ollama serve
最后,在单独的 shell 中运行模型:
./ollama run llama2
废话说完了
看看实际的效果图:
Mac
机器型号: M1芯片 16G
模型: qwen:1.8b
Linux
机器型号: 16C 32G 无显卡
模型: qwen:7b
用中文推荐使用 阿里的千问 qwen
对不住兄弟们,我原本以为支持上传视频呢,结果不支持,兄弟们先将就看看,欢迎下面留言,评论
不足之处:
- 暂时不支持 openai接口协议
- 涉及到的中文模型较少
不写了,准备过年了 兄弟们提前新年快乐!!!