Ubuntu20.04 私有化部署 Ollama + DeepSeek + Dify,构建你的专属私人 AI 助手
本机硬件:
1. 安装 Ollama:
curl -fsSL https://ollama.com/install.sh | sh
ollama -v
显存要求:
ollama run deepseek-r1:7b
用手机网络就是快,能达到 40MB/s
在快下载完的时候,速度非常慢,只有 32k/s 不知道最后啥情况: ctrl+c 杀掉,再重新运行就变快完成了。
7b 在我的硬件上,体验速度非常快!
2. 安装 Dify
为了不仅仅在命令行进行体验,我们安装 Dify
https://github.com/langgenius/dify-docs/blob/main/zh_CN/learn-more/use-cases/private-ai-ollama-deepseek-dify.md
https://docs.dify.ai/zh-hans/getting-started/install-self-hosted/docker-compose
git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env
docker compose up -d # 如果版本是 Docker Compose V1,使用以下命令:docker-compose up -d
docker compose ps
3. 访问 Dify
你可以先前往管理员初始化页面设置设置管理员账户:
# 本地环境
http://localhost/install
然后再使用设置的 邮箱和 密码进行登录。
会自动进入工作台:
http://localhost/apps
4. 将 DeepSeek 接入至 Dify
点击 Dify 平台右上角头像 → 设置 → 模型供应商,选择 Ollama,轻点“添加模型”。
最大上下文和最大 token 上限我在 https://help.aliyun.com/zh/model-studio/getting-started/models#935bd5ba5cg5d 查到的数据,不知道填的是不是对!也不知道填了有没有用!
An error occurred during credentials validation: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f63d8273830>: Failed to establish a new connection: [Errno 111] Connection refused'))
要设置为 你的 pc 的 ip:
sudo systemctl edit ollama.service
[Service]
Environment="OLLAMA_HOST=0.0.0.0"
systemctl daemon-reload
systemctl restart ollama
或者,我看到有人这么解决:
https://github.com/langgenius/dify/issues/2540#issuecomment-2116473095
检测界面能看到推理速度:http://localhost/apps
5. 基于本地知识库进行对话
参考: https://juejin.cn/post/7468566313339453480
添加Embedding模型: https://ollama.com/search?c=embedding&q=embedding
上传的资料要通过Embedding模型转换为向量数据存入向量数据库,这样回答问题时,才能根据自然语言,准确获取到原始数据的含义并召回,因此我们需要提前将私有数据向量化入库。
下载 Embedding 模型:
ollama pull bge-m3
配置 Embedding 模型:
步骤参考上述文档。
下了一个知识库:https://dl.djicdn.com/downloads/Mavic_Air_2/Mavic_Air_2_User_Manual_v1.0_cn_.pdf
7b 没有 14b 的效果好!
看起来结果都是对的!