安裝Json解析工具
Linux/Unix
sudo apt-get install jq -y
MacOS
brew install jq -y
設置環境變量
export IP="192.168.250.229"
export PORT="8080"
export MODEL="deepseek-r1:7b"
檢查Ollama版本
curl http://"$IP":"$PORT"/api/version
查看Ollama中的模型
curl http://"$IP":"$PORT"/api/tags | jq
為Ollama拉取模型
curl http://"$IP":"$PORT"/api/pull -d '{"model":"'"$MODEL"'"}'
為Ollama加載模型
curl http://"$IP":"$PORT"/api/chat -d '{"model": "'"$MODEL"'","messages": []
}'
讓模型響應一下
curl http://"$IP":"$PORT"/api/generate -d '{"model": "'"$MODEL"'","prompt":"Why is the sky blue?"
}'
和大模型聊一句(流式處理)
curl http://"$IP":"$PORT"/api/chat -d '{"model": "'"$MODEL"'","messages": [{"role": "user","content": "hello"}]
}'
再聊一句(無流式處理)
curl http://"$IP":"$PORT"/api/chat -d '{"model": "'"$MODEL"'","messages": [{"role": "user","content": "hello"}],"stream": false
}'
當前正在運行的模型
curl http://"$IP":"$PORT"/api/ps | jq
卸載模型
curl http://"$IP":"$PORT"/api/chat -d '{"model": "'"$MODEL"'","messages": [],"keep_alive": 0
}'
顯示模型信息
curl http://"$IP":"$PORT"/api/show -d '{"model": "'"$MODEL"'"
}' | jq
刪除模型
curl -X DELETE http://"$IP":"$PORT"/api/delete -d '{"model": "'"$MODEL"'"
}'
生成嵌入
curl http://"$IP":"$PORT"/api/embed -d '{"model": "nomic-embed-text","input": "Why is the sky blue?"
}'
curl http://"$IP":"$PORT"/api/embeddings -d '{"model": "nomic-embed-text","prompt": "Here is an article about llamas..."
}'