在无法访问huggingface或公网的Linux环境下,使用ollama,搭配qwen模型体验问答能力。
安装ollama
根据官网教程 Linux手动安装
Download the ollama binary
Ollama is distributed as a self-contained binary. Download it to a directory in your PATH:
1 2 3
| sudo curl -L https://ollama.com/download/ollama-linux-amd64 -o /usr/bin/ollama sudo chmod +x /usr/bin/ollama
|
Adding Ollama as a startup service (recommended)
Create a user for Ollama:
1
| sudo useradd -r -s /bin/false -m -d /usr/share/ollama ollama
|
Create a service file in /etc/systemd/system/ollama.service:
1 2 3 4 5 6 7 8 9 10 11 12 13
| [Unit] Description=Ollama Service After=network-online.target
[Service] ExecStart=/usr/bin/ollama serve User=ollama Group=ollama Restart=always RestartSec=3
[Install] WantedBy=default.target
|
Then start the service:
1 2
| sudo systemctl daemon-reload sudo systemctl enable ollama
|
Install CUDA drivers (optional – for Nvidia GPUs) 可选步骤
Download and install CUDA.
Verify that the drivers are installed by running the following command, which should print details about your GPU:
Start Ollama
Start Ollama using systemd:
1
| sudo systemctl start ollama
|
配置ollama
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
| mkdir /root/ollama/models export OLLAMA_MODELS=/root/ollama/models
ollama serve
cd /root/ollama/models wget https://huggingface.co/Qwen/Qwen2-0.5B-Instruct-GGUF/resolve/main/qwen2-0_5b-instruct-q8_0.gguf?download=true
cat > Modelfile.txt <<EOF FROM ./qwen2-0_5b-instruct-q8_0.gguf
# 以下命令参考ollama官网针对千问的示例 TEMPLATE """{{ if .System }}<|im_start|>system {{ .System }}<|im_end|> {{ end }}{{ if .Prompt }}<|im_start|>user {{ .Prompt }}<|im_end|> {{ end }}<|im_start|>assistant {{ .Response }}<|im_end|> """
PARAMETER stop "<|im_start|>" PARAMETER stop "<|im_end|>"
EOF
ollama create qwen0.5b -f Modelfile.txt
ollama run qwen0.5b
/bye
|
运行结果
1 2 3 4 5 6 7 8
| root@ubuntu:/tmp# ollama run qwen0.5b >>> 以李白的风格写一首七言绝句 月照孤舟客,灯烧古道人。
心随流水逝,梦入仙宫迷。
>>> /bye
|