DIFY开发环境搭建
作者:企起期小编 阅读次数:

docker-compose 方式

快速启动

启动 Dify 服务器的最简单方法是运行我们的 docker-compose.yml 文件。在运行安装命令之前,请确保您的机器上安装了 Docker Docker Compose

cd docker

docker-compose up -d   (经过测试,启动成功)

运行后,可以在浏览器上访问 http://localhost/install 进入 Dify 控制台并开始初始化安装操作。

本地开发

后端环境

D:\aiWorkspace> git clone https://github.com/langgenius/dify.git
D:\aiWorkspace>cd dify
D:\aiWorkspace\dify>cd api
D:\aiWorkspace\dify\api>python -m venv venv   #创建dify的虚拟运行环境,避免包的版本冲突
D:\aiWorkspace\dify\api>venv\Scripts\activate #启动dify的虚拟python运行环境
[root@unassigned api]# source /www/wwwroot/dify/api/venv/bin/activate #linux下启动虚拟Python环境


(venv) D:\aiWorkspace\dify\api>pip install -r requirements.txt   #在虚拟环境中安装对应版本包

#############安装完包后,要在linux环境安装redis,pg-sql,Weaviate(向量数据库) 等数据库或环境
[root@vmcentos8 docker]# docker-compose -f docker-compose.middleware.yaml up -d #docker方式启动中间件
WARN[0000] Found orphan containers ([docker-nginx-1 docker-worker-1 docker-api-1 docker-web-1]) for this prot up. 
[+] Running 3/3
 ⠿ Container docker-redis-1     Started                                                                     
 ⠿ Container docker-weaviate-1  Started                                                                     
 ⠿ Container docker-db-1        Started

# 以下是开放对应的端口
[root@vmcentos8 docker]# firewall-cmd --add-port=8080/tcp --permanent
success
[root@vmcentos8 docker]# firewall-cmd --add-port=6379/tcp --permanent
success
[root@vmcentos8 docker]# firewall-cmd --add-port=5432/tcp --permanent
success
[root@vmcentos8 docker]# firewall-cmd --reload
success
[root@vmcentos8 docker]# firewall-cmd --list-ports
22/tcp 80/tcp 5432/tcp 6379/tcp 8080/tcp 39002/tcp

[root@vmcentos8 docker]# openssl rand -base64 42 #生成秘钥


######以下是在vscode里面配置系统的环境
Copy .env.example to .env ###参考下方的.evn文件,主要是配置秘钥已经中间件的ip地址和端口

###以下是用flask db命令初始化数据库
(venv) [root@unassigned api]# flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 64b051264f32, init
INFO  [alembic.runtime.migration] Running upgrade 64b051264f32 -> 9f4e3427ea84, add created by role
INFO  [alembic.runtime.migration] Running upgrade 9f4e3427ea84 -> a45f4dfde53b, add language to recommend apps
'

#######以下是用debug方式启动后端api   #######################
(venv) D:\aiWorkspace\dify\api>flask run --host 0.0.0.0 --port=5001 --debug
 * Debug mode: on
INFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production
 WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5001
 * Running on http://192.168.1.3:5001
INFO:werkzeug:Press CTRL+C to quit
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 114-212-881

###按照下列方式启动dify api配置
Setup your application by visiting http://localhost:5001/console/api/setup or other apis...
If you need to debug local async processing, you can run celery -A app.celery worker, celery can do dataset importing and other async tasks.

###后端环境配置完毕##############################################
# Server Edition
EDITION=SELF_HOSTED

# Your App secret key will be used for securely signing the session cookie
# Make sure you are changing this key for your deployment with a strong key.
# You can generate a strong key using `openssl rand -base64 42`.
# Alternatively you can set it with `SECRET_KEY` environment variable.
SECRET_KEY=KIcpt1YGncmH/HQw7KyasUhFMY2z4mzFnnxkd3xnzE62LdnlNXXsvn01

# Console API base URL
CONSOLE_URL=http://localhost:5001  #必须要和3000都配置成localhost,相同域名,否则不让登陆

# Service API base URL
API_URL=http://localhost:5001

# Web APP base URL
APP_URL=http://localhost:5001

# celery configuration
CELERY_BROKER_URL=redis://:difyai123456@192.168.1.4:6379/1

# redis configuration
REDIS_HOST=192.168.1.4
REDIS_PORT=6379
REDIS_PASSWORD=difyai123456
REDIS_DB=0

# PostgreSQL database configuration
DB_USERNAME=postgres
DB_PASSWORD=difyai123456
DB_HOST=192.168.1.4
DB_PORT=5432
DB_DATABASE=dify

# Storage configuration
# use for store upload files, private keys...
# storage type: local, s3
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=storage
S3_ENDPOINT=https://your-bucket-name.storage.s3.clooudflare.com
S3_BUCKET_NAME=your-bucket-name
S3_ACCESS_KEY=your-access-key
S3_SECRET_KEY=your-secret-key
S3_REGION=your-region

# CORS configuration
WEB_API_CORS_ALLOW_ORIGINS=http://localhost:3000,*
CONSOLE_CORS_ALLOW_ORIGINS=http://localhost:3000,*

# Cookie configuration
COOKIE_HTTPONLY=true
COOKIE_SAMESITE=Lax
COOKIE_SECURE=false

# Session configuration
SESSION_PERMANENT=true
SESSION_USE_SIGNER=true

## support redis, sqlalchemy
SESSION_TYPE=redis

# session redis configuration
SESSION_REDIS_HOST=192.168.1.4
SESSION_REDIS_PORT=6379
SESSION_REDIS_PASSWORD=difyai123456
SESSION_REDIS_DB=2

# Vector database configuration, support: weaviate, qdrant
VECTOR_STORE=weaviate

# Weaviate configuration
WEAVIATE_ENDPOINT=http://192.168.1.4:8080
WEAVIATE_API_KEY=WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
WEAVIATE_GRPC_ENABLED=false

# Qdrant configuration, use `path:` prefix for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode
QDRANT_URL=path:storage/qdrant
QDRANT_API_KEY=your-qdrant-api-key

# Sentry configuration
SENTRY_DSN=

# DEBUG
DEBUG=false
SQLALCHEMY_ECHO=false

前端环境

D:\aiWorkspace\dify\web>nvm list  #查看当前node的版本

  * 16.14.2 (Currently using 64-bit executable)
    12.22.12

D:\aiWorkspace\dify\web>pnpm dev #发现pnpm没有安装
'pnpm' is not recognized as an internal or external command,
operable program or batch file.

D:\aiWorkspace\dify\web>npm install pnpm -g  #给当前node安装pnpm
D:\aiWorkspace\dify\web>pnpm install  #按照dify项目node需要的包

D:\aiWorkspace\dify\web>pnpm dev	' ###启动dify项目'

> dify-web@0.2.0 dev D:\aiWorkspace\dify\web
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn  - You have enabled experimental feature (appDir) in next.config.js.
info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at
 your own risk.

info  - VS Code settings.json has been created for Next.js' automatic app types, this file can be added to .gitignore if
 desired
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the
 following URL:
https://nextjs.org/telemetry

info  - automatically enabled Fast Refresh for 1 custom loader
event - compiled client and server successfully in 1627 ms (262 modules)
wait  - compiling...
event - compiled client and server successfully in 214 ms (262 modules)
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=PRODUCTION
# The deployment edition, SELF_HOSTED or CLOUD
NEXT_PUBLIC_EDITION=SELF_HOSTED
# The base URL of console application, refers to the Console base URL of WEB service if console domain is
# different from api or web app domain.
# example: http://cloud.dify.ai/console/api
NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api  #必须是localhost和web要一样,否则各种稀奇古怪的错
# The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
# console or api domain.
# example: http://udify.app/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api

# SENTRY
NEXT_PUBLIC_SENTRY_DSN=
NEXT_PUBLIC_SENTRY_ORG=
NEXT_PUBLIC_SENTRY_PROJECT=


返回列表

扫码关注不迷路!!!

郑州升龙商业广场B座25层

service@iqiqiqi.cn

企起期科技 qiqiqi

联系电话:400-8049-474

联系电话:187-0363-0315

联系电话:199-3777-5101