到目前為止,我們已經完成了:
接下來,真正的主角要登場了:Ollama。
市面上有很多本地 LLM 的選擇,例如:
而 Ollama 的定位是:
換句話說,Ollama 就像是 「Docker for LLM」 —— 你只要拉取映像檔(模型),就能立即啟動。
在 Ubuntu 上只需要一行指令:
curl -fsSL https://ollama.com/install.sh | sh
安裝過程中會:
安裝完成後,執行:
ollama --version
若出現版本號(例如 ollama version 0.1.34
),代表安裝成功。
Ollama 預設只綁 127.0.0.1
,要改綁全介面
用 systemd 服務,永久化設定
sudo systemctl edit ollama
貼入:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
儲存後:
sudo systemctl daemon-reload
sudo systemctl restart ollama
sudo systemctl status ollama
Ollama 下載一個小模型 llama3,可以直接執行:
ollama run llama3
輸入問題:
> 你好,請用一句話介紹你自己
模型會回覆:
Hello! 🤗 I'm LLaMA, a large language model trained by AI to understand
and respond to human input in a helpful and engaging way, with the goal of
assisting and communicating effectively. 😊
這代表 Ollama 已經能正常工作。
Step 3:測試 API
Ollama 的強大之處在於提供 REST API,這讓我們能在後續用 Python、Web UI、Discord Bot 串接。
測試 API:
curl http://localhost:11434/api/generate -d '{
"model": "llama3",
"prompt": "請用繁體中文解釋 AI 是什麼?"
}'
這意味著:
Ollama 的一些常用指令:
查看已安裝模型:
ollama list
移除模型:
ollama rm <模型名稱>
停止服務:
sudo systemctl stop ollama
啟動服務:
sudo systemctl start ollama