网站维护的工作内容,深圳网站设计公司哪家专业,石油网站编辑怎么做,国外域名注册网站Dify 介绍
Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务#xff08;Backend as Service#xff09;和 LLMOps 的理念#xff0c;使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员#xff0c;也能参与到 AI 应用的定义和数据运营过…Dify 介绍
Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务Backend as Service和 LLMOps 的理念使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员也能参与到 AI 应用的定义和数据运营过程中。
由于 Dify 内置了构建 LLM 应用所需的关键技术栈包括对数百个模型的支持、直观的 Prompt 编排界面、高质量的 RAG 引擎以及灵活的 Agent 框架并同时提供了一套易用的界面和 API。这为开发者节省了许多重复造轮子的时间使其可以专注在创新和业务需求上。 Clone Dify 代码
git clone https://github.com/langgenius/dify.git 前端环境搭建
安装nodejs
Web 前端服务启动需要用到 Node.js v18.x (LTS) 、NPM 版本 8.x.x 或 Yarn。选择对应操作系统的 v18.x 以上的安装包下载并安装建议 stable 版本已自带 NPM。
详见Mac 安装Nodejs
启动步骤
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 SystemSoftwareDescription 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
Docker Desktop 下载安装即可。
安装Docker之后进行版本验证
(base) % docker-compose -versiondocker-compose version 1.29.2, build 5becea4c(base) % docker --versionDocker version 20.10.7, build f0df350
Anaconda 安装 详见MAC 安装miniconda
# 创建名为 dify 的 Python 3.10 环境
conda create --name dify python3.10
# 切换至 dify Python 环境
conda activate dify
Python 3.10.x 安装
有些mac出厂自带python但是版本可能不是最新的大家可以试试自己的Mac测试步骤是1打开terminal终端2输入命令python或者python3如果出现python的版本号则代表已经安装但还是推荐大家进行更新无需卸载旧版本直接安装新版本即可
Download Python | Python.org
Git 安装
brew install git
验证 git version显示版本号就说明安装成功了。
git version
git version 2.39.3 (Apple Git-146) PostgreSQL 安装
1.安装命令brew install postgresql
brew install postgresql
2. 检查是否安装成功 brew list
% brew listFormulae
abseil krb5 pcre2
aws-elasticbeanstalk libiconv postgresql14
brotli libmagic protobuf
c-ares libnghttp2 protobuf-c
ca-certificates libuv python3.10
certifi libyaml python3.11
clamav lz4 readline
gdbm mc redis
gradle mpdecimal sqlite
icu4c node xz
jansson openjdk yara
json-c openssl1.1
jsoncpp openssl3 Casks
jd-gui table-tool
3. 启动 brew services start postgresql
% brew services start postgresql
Warning: Formula postgresql was renamed to postgresql14.Successfully started postgresql14 (label: homebrew.mxcl.postgresql14)
4. 检查是否启动成功 brew services list
% brew services list
Name Status User File
clamav none
postgresql14 started rsun ~/Library/LaunchAgents/homebrew.mxcl.postgresql14.plist
redis started rsun ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
5. 初始化数据库
initdb /usr/local/var/postgres
6. 创建user
createuser -s postgres
Redis 安装
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.
启动DIfy后端
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 modulefrom gevent import monkey
ModuleNotFoundError: No module named gevent
解决办法
pip install -U --force-reinstall --no-binary :all: gevent6. 启动 API 服务 flask run --host 0.0.0.0 --port5001 --debug 7. 启动 worker 服务
用于消费异步队列任务如数据集文件导入、更新数据集文档等异步操作。 MacOS 启动
celery -A app.celery worker -P gevent -c 1 -Q dataset,generation,mail --loglevel INFO
总结
以上为本地源码部署启动的Dify方式。
下次进入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 --port5001 --debug
4.前端程序
cd web目录
启动 web 服务 npm run start