dify二开示例

707 阅读1分钟

一、前言

1.1、前置知识

需要您在本地能够启动部署dify,如果没有到这一步,请移步文章《ollama+dify本地化部署【菜鸟教程】》

1.2、实现效果

原先效果

image.png

最终效果 image.png

以上方式,仅仅只是个示例,如果您想更换dify图标,可以去dify-1.5.0\web\public\logo文件夹下替换所有的

二、更改前端

2.1、dify-1.5.0版本

1)复制env文件 image.png

2)进入dify-1.5.0\web\app\components\base\chat\embedded-chatbot\header\index.tsx文件下

image.png

3)更改前端代码完毕后,进入 dify-1.5.0/docker,更改docker-compose.yaml文件

  # Frontend web application.
  web:
    #image: langgenius/dify-web:1.5.0
    image: dify-web-custom

下图所示 1753768609747_73CBAE43-3F40-4d26-BF56-7125416F59BD.png

更改完毕后,执行命令将web目录打包成本地镜像web,docker compose up -d dify-web-custom Image.png 打包花的时间比较久,需要耐心等待 Image.png

4)docker compose up -d,重启docker image.png

5)最终效果为 image.png

三、更改后端

3.1、dify版本1.0.0-1.2.0

1)复制env文件 image.png

2)更改后端代码,代码位于dify\api image.png api是python开发,用的打包工具是poetry,先安装poetry

pip install poetry

进入api目录然后执行

poetry install

编辑api目录下的Dockerfile


# Install Python dependencies
# COPY pyproject.toml poetry.lock ./
# RUN poetry install --sync --no-cache --no-root

# Install Python dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry source add mirrors https://mirrors.aliyun.com/pypi/simple/
RUN poetry lock
RUN poetry install --no-root

image.png

3)回到dify/docker目录,编辑docker-compose.yaml里找到api的镜像配置改成

  api:
    # image: langgenius/dify-api:1.0.0
    image: dify-api-custom

image.png

4)最后执行,docker build -t dify-api-custom ../api

image.png

3.2、dify版本1.5.0

1)复制env文件 image.png

2)1.5版本的工具变成了uv image.png

3)回到dify/docker目录,编辑docker-compose.yaml里找到api的镜像配置改成

  # API service
  api:
    # image: langgenius/dify-api:1.5.0
    image: dify-api-custom

image.png

4)最后执行,docker build -t dify-api-custom ../api

image.png

四、总结

上文只是一个简单的示例,更加复杂的二开,需要您自己去探索开发了,完结撒花....