ollama使用教程

安装

1
docker run -d --cpus="8.0" --memory="16g" -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama  # 加速docker.1ms.run

拉取模型

1
docker exec -it ollama    ollama pull qwen2.5:3b

对话交互

1
docker exec -it ollama    ollama run qwen2.5:3b

API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 查看ollama版本
curl http://localhost:11434/api/version


# 查看本地模型
curl http://localhost:11434/api/tags
# 查看当前加载进内存的模型
curl http://localhost:11434/api/ps
# 查看模型信息
curl http://localhost:11434/api/show -d '{"model": "llama3.2"}'


# 增加模型(远程拉取模型)
curl http://localhost:11434/api/pull -d '{"model": "llama3:13b"}'
# 删除模型(从本地删除)
curl -X DELETE http://localhost:11434/api/delete -d '{"model": "llama3:13b"}'
# 复制模型(从已存在的模型中,复制出一个名字不同的相同模型)
curl http://localhost:11434/api/copy -d '{"source": "llama3.2", "destination": "llama3.2-backup"}'


# 生成Embedding
curl http://localhost:11434/api/embed -d '{
"model": "all-minilm",
"input": "Why is the sky blue?"
}'

# 文本补全
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"stream": false,
"options": {"temperature": 0, "seed": 123},
"prompt": "Why is the sky blue?"
}'

# 对话聊天
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"stream": false,
"options": {"temperature": 0.7, "seed": 123},
"messages": [
{
"role": "user",
"content": "why is the sky blue?"
}
]
}'

参考资料