【原创】Ollama Test API For Linux/MacOS/Unix
安装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..."
}'