Dify+DeepSeek部署本地大模型实现RAG

安装Dify

Dify是一个基于GPT的AI应用开发平台,支持多种大语言模型(LLM),旨在帮助用户快速创建和运营生成式AI原生应用。它具备以下特点:

  • 多模型支持:兼容OpenAI、Claude、Hugging Face等主流模型,并支持本地私有化部署。
  • 可视化编排:提供Prompt模板、工具链等可视化工具,简化应用开发流程。
  • 丰富功能:支持文本生成、对话、知识库问答等,满足多样化需求。
  • 灵活部署:支持云服务和本地部署,适应不同场景。
  • 持续更新:团队持续优化,确保平台功能与时俱进。
  • Dify适合开发者、企业和个人用户,用于构建智能客服、内容生成、教育辅助等AI应用。diay代码地址:https://gitee.com/dify_ai/dify,把代码克隆下来

本地部署dify

系统信息:
Ubuntu22.04
Docker version 26.1.3, build 26.1.3-0ubuntu1~22.04.1
docker-compose version 1.29.2, build unknown

Ubuntu Docker 安装

手动安装

卸载旧版本
Docker 的旧版本被称为 docker,docker.io 或 docker-engine 。如果已安装,请卸载它们:

$ sudo apt-get remove docker docker-engine docker.io containerd runc

当前称为 Docker Engine-Community 软件包 docker-ce 。

安装 Docker Engine-Community,以下介绍两种方式。

** 使用 Docker 仓库进行安装 **
在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker 。

设置仓库
更新 apt 包索引。

$ sudo apt-get update

安装 apt 依赖包,用于通过HTTPS来获取仓库:

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

添加 Docker 的官方 GPG 密钥:

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

使用以下指令设置稳定版仓库

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

安装 Docker Engine-Community
更新 apt 包索引。

$ sudo apt-get update

安装最新版本的 Docker Engine-Community 和 containerd ,或者转到下一步安装特定版本:

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

要安装特定版本的 Docker Engine-Community,请在仓库中列出可用版本,然后选择一种安装。列出您的仓库中可用的版本:

$ apt-cache madison docker-ce

  docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 18.06.1~ce~3-0~ubuntu       | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 18.06.0~ce~3-0~ubuntu       | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
  ...

使用第二列中的版本字符串安装特定版本,例如 5:18.09.1~3-0~ubuntu-xenial。

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

例如安装 26.1.3 版本

$ sudo apt-get install docker-ce=5:26.1.3-1~ubuntu.22.04~jammy docker-ce-cli=5:26.1.3-1~ubuntu.22.04~jammy containerd.io

安装过程中遇到的问题

1. sudo systemctl start docker
报 如下错误:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down


换成  $ sudo service docker start  ,又报如下错误

$ sudo service docker start 报如下错误,
错误:
/etc/init.d/docker: 62: ulimit: error setting limit (Invalid argument)

# 则 
sudo vi /etc/init.d/docker
# 找到 这一行代码 
ulimit -Hn 524288

# Remove the -H argument, changing the line to: 将 H 移除掉
ulimit -n 524288

如下图所示 在这里插入图片描述

测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:

https://blog.csdn.net/qq_40351360/article/details/125467093

https://developer.aliyun.com/article/1519211

http://qa.anyline.org/v/58_15247

https://blog.csdn.net/weixin_42152531/article/details/120416296

#dify源码获取
git clone --branch 0.15.3 --depth 1 https://gitee.com/dify_ai/dify.git 
cd dify/docker # 关键目录
cp .env.example .env # 复制环境变量模板
sudo docker-compose up -d # 后台启动docker,会自动拉取镜像
$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest


Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

在这里插入图片描述
代码解压后,进入到 docker 目录后,将.env.example 复制一份修改为:.env 该文件是dify的环境配置文件, 然后通过CMD在当前目录执行:docker compose up -d

sudo systemctl daemon-reload
如果提示/usr/bin/systemctl:1628: SyntaxWarning: invalid escape sequence ‘\w’
找到\w改成\w
如果提示ERROR:systemctl: dbus.service: Executable path is not absolute, ignoring: @/usr/bin/dbus-daemon @dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
打开/lib/systemd/system/dbus.service 把@符号删除

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐