赞
踩
Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务(Backend as Service)和 LLMOps 的理念,使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员,也能参与到 AI 应用的定义和数据运营过程中。
由于 Dify 内置了构建 LLM 应用所需的关键技术栈,包括对数百个模型的支持、直观的 Prompt 编排界面、高质量的 RAG 引擎以及灵活的 Agent 框架,并同时提供了一套易用的界面和 API。这为开发者节省了许多重复造轮子的时间,使其可以专注在创新和业务需求上。
Clone Dify 代码:
git clone https://github.com/langgenius/dify.git
Web 前端服务启动需要用到 Node.js v18.x (LTS) 、NPM 版本 8.x.x 或 Yarn。选择对应操作系统的 v18.x 以上的安装包下载并安装,建议 stable 版本,已自带 NPM。
(1)进入 web 目录 cd web
(2)安装依赖包 npm install
(3)配置环境变量。在当前目录下/web下创建文件 .env.local,并复制.env.example中的内容
(4)构建代码 npm run build
(5)启动 web 服务 npm run start
(6)访问:访问 http://127.0.0.1:3000
Operating System | Software | Description |
---|---|---|
macOS 10.14 or later | Docker Desktop | Set the Docker Virtual Machine (VM) to use at least 2 virtual CPUs (vCPU) and 8 GB of initial memory. Otherwise, the installation may fail. For more information, see Install Docker Desktop on Mac. |
Linux platforms | Docker 19.03 or later Docker Compose 1.25.1 or later | 请参阅安装 Docker 和安装 Docker Compose 以获取更多信息。 |
Windows with WSL 2 enabled | Docker Desktop |
我的操作系统是mac,直接进行Docker Desktop安装即可。
Docker Desktop 下载安装即可。
安装Docker之后进行版本验证
- (base) % docker-compose -version
-
- docker-compose version 1.29.2, build 5becea4c
-
- (base) % docker --version
-
- Docker version 20.10.7, build f0df350
- # 创建名为 dify 的 Python 3.10 环境
- conda create --name dify python=3.10
- # 切换至 dify Python 环境
- conda activate dify
有些mac出厂自带python,但是版本可能不是最新的,大家可以试试自己的Mac,测试步骤是:(1)打开terminal终端(2)输入命令:python或者python3,如果出现python的版本号则代表已经安装,但还是推荐大家进行更新,无需卸载旧版本,直接安装新版本即可
brew install git
验证 git version,显示版本号就说明安装成功了。
- git version
- git version 2.39.3 (Apple Git-146)
1.安装命令:brew install postgresql
brew install postgresql
2. 检查是否安装成功 brew list
% brew list ==> Formulae abseil krb5 pcre2 aws-elasticbeanstalk libiconv postgresql@14 brotli libmagic protobuf c-ares libnghttp2 protobuf-c ca-certificates libuv python@3.10 certifi libyaml python@3.11 clamav lz4 readline gdbm mc redis gradle mpdecimal sqlite icu4c node xz jansson openjdk yara json-c openssl@1.1 jsoncpp openssl@3 ==> Casks jd-gui table-tool
3. 启动 brew services start postgresql
- % brew services start postgresql
- Warning: Formula postgresql was renamed to postgresql@14.
- ==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
4. 检查是否启动成功 brew services list
- % brew services list
- Name Status User File
- clamav none
- postgresql@14 started rsun ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
- redis started rsun ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
5. 初始化数据库
initdb /usr/local/var/postgres
6. 创建user
createuser -s postgres
1.安装 brew install redis
2. 启动Redis brew services start redis
- % brew services start redis
- Service `redis` already started, use `brew services restart redis` to restart.
1.进入 api 目录 cd api
2. 复制环境变量配置文件
cp .env.example .env
3. 生成随机密钥,并替换 .env 中 SECRET_KEY 的值
openssl rand -base64 42
vim .env 打开 .env文件,修改SECRET_KEY=新生成的key
4. 安装依赖包 pip3 install -r requirements.txt
5. 执行数据库迁移将数据库结构迁移至最新版本。
flask db upgrade
- flask db upgrade
- * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
- Error: While importing 'app', an ImportError was raised:
-
- Traceback (most recent call last):
- File "/Users/rsun/miniconda3/lib/python3.12/site-packages/flask/cli.py", line 245, in locate_app
- __import__(module_name)
- File "/Users/rsun/software/dify-main/api/app.py", line 6, in <module>
- from gevent import monkey
- ModuleNotFoundError: No module named 'gevent'
-
解决办法:
pip install -U --force-reinstall --no-binary :all: gevent
6. 启动 API 服务
flask run --host 0.0.0.0 --port=5001 --debug
7. 启动 worker 服务
用于消费异步队列任务,如数据集文件导入、更新数据集文档等异步操作。 MacOS 启动:
celery -A app.celery worker -P gevent -c 1 -Q dataset,generation,mail --loglevel INFO
以上为本地源码部署启动的Dify方式。
启动:
1. conda activate dify
2. Redis: brew services restart redis
3. Postgresql: brew services start postgresql
4.后端程序:
cd api目录
flask run --host 0.0.0.0 --port=5001 --debug
4.前端程序:
cd web目录
启动 web 服务 npm run start
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。