当前位置:   article > 正文

MAC 本地搭建Dify环境_dify中文版mac部署

dify中文版mac部署

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之后进行版本验证

  1. (base) % docker-compose -version
  2. docker-compose version 1.29.2, build 5becea4c
  3. (base) % docker --version
  4. Docker version 20.10.7, build f0df350

Anaconda 安装

详见MAC 安装miniconda

  1. # 创建名为 dify 的 Python 3.10 环境
  2. conda create --name dify python=3.10
  3. # 切换至 dify Python 环境
  4. 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,显示版本号就说明安装成功了。

  1. git version
  2. git version 2.39.3 (Apple Git-146)

 PostgreSQL 安装

1.安装命令:brew install postgresql

brew install postgresql

2. 检查是否安装成功 brew list

  1. % brew list
  2. ==> Formulae
  3. abseil krb5 pcre2
  4. aws-elasticbeanstalk libiconv postgresql@14
  5. brotli libmagic protobuf
  6. c-ares libnghttp2 protobuf-c
  7. ca-certificates libuv python@3.10
  8. certifi libyaml python@3.11
  9. clamav lz4 readline
  10. gdbm mc redis
  11. gradle mpdecimal sqlite
  12. icu4c node xz
  13. jansson openjdk yara
  14. json-c openssl@1.1
  15. jsoncpp openssl@3
  16. ==> Casks
  17. jd-gui table-tool

3. 启动 brew services start postgresql

  1. % brew services start postgresql
  2. Warning: Formula postgresql was renamed to postgresql@14.
  3. ==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)

4. 检查是否启动成功  brew services list

  1. % brew services list
  2. Name Status User File
  3. clamav none
  4. postgresql@14 started rsun ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
  5. 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

  1. % brew services start redis
  2. 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

  1. flask db upgrade
  2. * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
  3. Error: While importing 'app', an ImportError was raised:
  4. Traceback (most recent call last):
  5. File "/Users/rsun/miniconda3/lib/python3.12/site-packages/flask/cli.py", line 245, in locate_app
  6. __import__(module_name)
  7. File "/Users/rsun/software/dify-main/api/app.py", line 6, in <module>
  8. from gevent import monkey
  9. 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方式。

下次进入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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/577054
推荐阅读
相关标签
  

闽ICP备14008679号