docs/libmagic step (#514)

* Docs: update a macos command

* Docs: update a macos command

* Docs: update action file
This commit is contained in:
AllenWriter
2025-02-14 16:32:00 +08:00
committed by GitHub
parent cc1f9b824c
commit 73748657da
5 changed files with 763 additions and 38 deletions
+9 -32
View File
@@ -4,7 +4,7 @@ on:
pull_request:
types: [opened, synchronize]
paths:
- '**.md'
- '**.md' # 只在 markdown 文件变更时触发
jobs:
lang-check:
@@ -14,7 +14,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0 # 获取完整的 git 历史,以便进行 diff 比较
- name: Setup Git
run: |
@@ -32,36 +32,13 @@ jobs:
run: |
chmod +x ./lang-check/git-diff.sh
output=$(./lang-check/git-diff.sh)
echo "$output"
echo "$output" # 显示检查结果
# Check ❌
# 检查输出中是否包含 ❌ 符号
if echo "$output" | grep -q "❌"; then
echo "Inspection found problems, PR Not approved"
exit 1 # Action run failed
echo "检查发现问题,PR 不予通过"
exit 1 # 非零退出码会导致 Action 失败
else
echo "Passed"
exit 0 # Action run successfully
fi
- name: Comment PR
if: always() # Run even if previous step fails
uses: actions/github-script@v7
with:
script: |
const output = `### Language Check Results 🔍
${process.env.RESULT}
Status: ${process.env.STATUS === 'passed' ? '✅ Passed' : '❌ Failed'}
*Automated message from Language Check Action*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
env:
RESULT: ${{ steps.check.outputs.result }}
STATUS: ${{ steps.check.outputs.status }}
echo "检查通过"
exit 0 # 零退出码表示 Action 成功
fi
@@ -59,19 +59,21 @@ pyenv global 3.12
cd api
```
2. Copy the environment variable configuration file:
> For macOS: install libmagic with `brew install libmagic`.
1. Copy the environment variable configuration file:
```
cp .env.example .env
```
3. Generate a random secret key and replace the value of SECRET_KEY in the .env file:
2. Generate a random secret key and replace the value of SECRET_KEY in the .env file:
```
awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env
```
4. Install the required dependencies:
3. Install the required dependencies:
Dify API service uses [Poetry](https://python-poetry.org/docs/) to manage dependencies. You can execute `poetry shell` to activate the environment.
@@ -80,7 +82,7 @@ pyenv global 3.12
poetry install
```
5. Perform the database migration:
4. Perform the database migration:
Perform database migration to the latest version:
@@ -89,7 +91,7 @@ pyenv global 3.12
flask db upgrade
```
6. Start the API server:
5. Start the API server:
```
flask run --host 0.0.0.0 --port=5001 --debug
@@ -108,7 +110,7 @@ pyenv global 3.12
INFO:werkzeug: * Debugger PIN: 695-801-919
```
7. Start the Worker service
6. Start the Worker service
To consume asynchronous tasks from the queue, such as dataset file import and dataset document updates, follow these steps to start the Worker service on Linux or macOS:
@@ -58,6 +58,8 @@ pyenv global 3.12
```
cd api
```
> macOSの場合:`brew install libmagic`でlibmagicをインストールしてください。
2. 環境変数構成ファイルをコピー
```
+742
View File
@@ -0,0 +1,742 @@
<start---lang-check/en/getting-started/install-self-hosted/local-source-code.md---start>
# Local Source Code Start
## Prerequisites
> Before installing Dify, make sure your machine meets the following minimum system requirements:
> - CPU >= 2 Core
> - RAM >= 4 GiB
| Operating System | Software | Explanation |
| -------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| macOS 10.14 or later | Docker Desktop | Set the Docker virtual machine (VM) to use a minimum of 2 virtual CPUs (vCPUs) and 8 GB of initial memory. Otherwise, the installation may fail. For more information, please refer to the [Docker Desktop installation guide for Mac](https://docs.docker.com/desktop/mac/install/). |
| Linux platforms | <p>Docker 19.03 or later<br>Docker Compose 1.25.1 or later</p> | Please refer to the [Docker installation guide](https://docs.docker.com/engine/install/) and [the Docker Compose installation guide](https://docs.docker.com/compose/install/) for more information on how to install Docker and Docker Compose, respectively. |
| Windows with WSL 2 enabled | <p>Docker Desktop<br></p> | We recommend storing the source code and other data that is bound to Linux containers in the Linux file system rather than the Windows file system. For more information, please refer to the [Docker Desktop installation guide for using the WSL 2 backend on Windows.](https://docs.docker.com/desktop/windows/install/#wsl-2-backend) |
> If you need to use OpenAI TTS, `FFmpeg` must be installed on the system for it to function properly. For more details, refer to: [Link](https://docs.dify.ai/getting-started/install-self-hosted/install-faq#id-14.-what-to-do-if-this-error-occurs-in-text-to-speech).
### Clone Dify
```Bash
git clone https://github.com/langgenius/dify.git
```
Before enabling business services, we need to first deploy PostgreSQL / Redis / Weaviate (if not locally available). We can start them with the following commands:
```Bash
cd docker
cp middleware.env.example middleware.env
docker compose -f docker-compose.middleware.yaml up -d
```
---
### Server Deployment
- API Interface Service
- Worker Asynchronous Queue Consumption Service
#### Installation of the basic environment:
Server startup requires Python 3.12. It is recommended to use [pyenv](https://github.com/pyenv/pyenv) for quick installation of the Python environment.
To install additional Python versions, use pyenv install.
```Bash
pyenv install 3.12
```
To switch to the "3.12" Python environment, use the following command:
```Bash
pyenv global 3.12
```
#### Follow these steps :
1. Navigate to the "api" directory:
```
cd api
```
> For macOS: install libmagic with `brew install libmagic`.
1. Copy the environment variable configuration file:
```
cp .env.example .env
```
2. Generate a random secret key and replace the value of SECRET_KEY in the .env file:
```
awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env
```
3. Install the required dependencies:
Dify API service uses [Poetry](https://python-poetry.org/docs/) to manage dependencies. You can execute `poetry shell` to activate the environment.
```
poetry env use 3.12
poetry install
```
4. Perform the database migration:
Perform database migration to the latest version:
```
poetry shell
flask db upgrade
```
5. Start the API server:
```
flask run --host 0.0.0.0 --port=5001 --debug
```
output
```
* 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
INFO:werkzeug:Press CTRL+C to quit
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 695-801-919
```
6. Start the Worker service
To consume asynchronous tasks from the queue, such as dataset file import and dataset document updates, follow these steps to start the Worker service on Linux or macOS:
```
celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
```
If you are using a Windows system to start the Worker service, please use the following command instead:
```
celery -A app.celery worker -P solo --without-gossip --without-mingle -Q dataset,generation,mail,ops_trace --loglevel INFO
```
output:
```
-------------- celery@TAKATOST.lan v5.2.7 (dawn-chorus)
--- ***** -----
-- ******* ---- macOS-10.16-x86_64-i386-64bit 2023-07-31 12:58:08
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app: app:0x7fb568572a10
- ** ---------- .> transport: redis://:**@localhost:6379/1
- ** ---------- .> results: postgresql://postgres:**@localhost:5432/dify
- *** --- * --- .> concurrency: 1 (gevent)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> dataset exchange=dataset(direct) key=dataset
.> generation exchange=generation(direct) key=generation
.> mail exchange=mail(direct) key=mail
[tasks]
. tasks.add_document_to_index_task.add_document_to_index_task
. tasks.clean_dataset_task.clean_dataset_task
. tasks.clean_document_task.clean_document_task
. tasks.clean_notion_document_task.clean_notion_document_task
. tasks.create_segment_to_index_task.create_segment_to_index_task
. tasks.deal_dataset_vector_index_task.deal_dataset_vector_index_task
. tasks.document_indexing_sync_task.document_indexing_sync_task
. tasks.document_indexing_task.document_indexing_task
. tasks.document_indexing_update_task.document_indexing_update_task
. tasks.enable_segment_to_index_task.enable_segment_to_index_task
. tasks.generate_conversation_summary_task.generate_conversation_summary_task
. tasks.mail_invite_member_task.send_invite_member_mail_task
. tasks.remove_document_from_index_task.remove_document_from_index_task
. tasks.remove_segment_from_index_task.remove_segment_from_index_task
. tasks.update_segment_index_task.update_segment_index_task
. tasks.update_segment_keyword_index_task.update_segment_keyword_index_task
[2023-07-31 12:58:08,831: INFO/MainProcess] Connected to redis://:**@localhost:6379/1
[2023-07-31 12:58:08,840: INFO/MainProcess] mingle: searching for neighbors
[2023-07-31 12:58:09,873: INFO/MainProcess] mingle: all alone
[2023-07-31 12:58:09,886: INFO/MainProcess] pidbox: Connected to redis://:**@localhost:6379/1.
[2023-07-31 12:58:09,890: INFO/MainProcess] celery@TAKATOST.lan ready.
```
---
## Deploy the frontend page
Start the web frontend client page service
#### Installation of the basic environment:
To start the web frontend service, you will need [Node.js v18.x (LTS)](http://nodejs.org/) and [NPM version 8.x.x](https://www.npmjs.com/) or [Yarn](https://yarnpkg.com/).
- Install NodeJS + NPM
Please visit [https://nodejs.org/en/download](https://nodejs.org/en/download) and choose the installation package for your respective operating system that is v18.x or higher. It is recommended to download the stable version, which includes NPM by default.
#### Follow these steps :
1. Enter the web directory
```
cd web
```
2. Install the dependencies.
```
npm install
```
3. Configure the environment variables. Create a file named .env.local in the current directory and copy the contents from .env.example. Modify the values of these environment variables according to your requirements:
```
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# 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
# 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=
```
4. Build the code
```
npm run build
```
5. Start the web service
```
npm run start
# or
yarn start
# or
pnpm start
```
After successful startup, the terminal will output the following information
```
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
```
### Access Dify
Finally, access [http://127.0.0.1:3000](http://127.0.0.1:3000/) to use the locally deployed Dify.
<end---/en/getting-started/install-self-hosted/local-source-code.md---end>
<start---lang-check/jp/getting-started/install-self-hosted/local-source-code.md---start>
# ローカルソースコード起動
### 前提条件
> Dify インストール前に, ぜひマシンが最小インストール要件を満たしていることを確認してください:
> - CPU >= 2 Core
> - RAM >= 4 GiB
| 操作系统 | ソフトウェア | 説明 |
| -------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| macOS 10.14またはそれ以降 | Docker Desktop | Docker 仮想マシン(VM)を少なくとも2つの仮想CPU(vCPU)と8GBの初期メモリを使用するように設定してください。そうでないと、インストールが失敗する可能性があります。詳細は[MacにDocker Desktopをインストールする](https://docs.docker.com/desktop/mac/install/)を参照してください。 |
| Linux プラットフォーム | <p>Docker 19.03またはそれ以降<br>Docker Compose 1.25.1またはそれ以降</p>| 詳細は[Dockerをインストールする](https://docs.docker.com/engine/install/)および[Docker Composeをインストールする](https://docs.docker.com/compose/install/)を参照してください。 |
| WSL 2が有効なWindows | Docker Desktop | ソースコードや他のデータをLinuxコンテナにバインドする際、WindowsファイルシステムではなくLinuxファイルシステムに保存することをお勧めします。詳細は[WSL 2バックエンドを使用してWindowsにDocker Desktopをインストールする](https://docs.docker.com/desktop/windows/install/#wsl-2-backend)を参照してください。 |
> OpenAI TTSを使用する場合、システムにFFmpegをインストールする必要があります。詳細は[リンク](https://docs.dify.ai/v/ja-jp/learn-more/faq/install-faq#id-15-tekisutomigeniopenai-error-ffmpeg-is-not-installedtoiuergashitano)を参照してください。
Dify コードをクローン:
```Bash
git clone https://github.com/langgenius/dify.git
```
ビジネスサービスを有効にする前に、PostgreSQL / Redis / Weaviate(ローカルにない場合)をデプロイする必要があります。以下のコマンドで起動できます:
```Bash
cd docker
docker compose -f docker-compose.middleware.yaml up -d
```
***
### サービスデプロイ
* API インターフェースサービス
* Worker 非同期キュー消費サービス
#### 基本環境インストール
サーバーの起動にはPython 3.12 が必要です。Python環境の迅速なインストールには[pyenv](https://github.com/pyenv/pyenv)を使用することをお勧めします。
追加のPythonバージョンをインストールするには、pyenv installを使用します。
```Bash
pyenv install 3.12
```
"3.12" の Python 環境に切り替えるには、次のコマンドを使用します。
```Bash
pyenv global 3.12
```
#### 起動手順
1. apiディレクトリに移動
```
cd api
```
> macOSの場合:`brew install libmagic`でlibmagicをインストールしてください。
2. 環境変数構成ファイルをコピー
```
cp .env.example .env
```
3. ランダムキーを生成し、`.env`の`SECRET_KEY`の値を置き換え
```
awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env
```
4. 依存関係をインストール
Dify APIサービスは依存関係を管理するために[Poetry](https://python-poetry.org/docs/)を使用します。環境を有効にするには、`poetry shell`を実行できます。
```
poetry env use 3.12
poetry install
```
5. データベース移行を実行
データベーススキーマを最新バージョンに更新します。
```
poetry shell
flask db upgrade
```
6. 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
INFO:werkzeug:Press CTRL+C to quit
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 695-801-919
```
7. Workerサービスを開始
データセットファイルのインポートやデータセットドキュメントの更新などの非同期操作を消費するためのサービスです。Linux / MacOSでの起動:
```
celery -A app.celery worker -P gevent -c 1 -Q dataset,generation,mail,ops_trace --loglevel INFO
```
Windowsシステムでの起動の場合、以下のコマンドを使用してください:
```
celery -A app.celery worker -P solo --without-gossip --without-mingle -Q dataset,generation,mail,ops_trace --loglevel INFO
```
正常な出力:
```
-------------- celery@TAKATOST.lan v5.2.7 (dawn-chorus)
--- ***** -----
-- ******* ---- macOS-10.16-x86_64-i386-64bit 2023-07-31 12:58:08
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app: app:0x7fb568572a10
- ** ---------- .> transport: redis://:**@localhost:6379/1
- ** ---------- .> results: postgresql://postgres:**@localhost:5432/dify
- *** --- * --- .> concurrency: 1 (gevent)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> dataset exchange=dataset(direct) key=dataset
.> generation exchange=generation(direct) key=generation
.> mail exchange=mail(direct) key=mail
[tasks]
. tasks.add_document_to_index_task.add_document_to_index_task
. tasks.clean_dataset_task.clean_dataset_task
. tasks.clean_document_task.clean_document_task
. tasks.clean_notion_document_task.clean_notion_document_task
. tasks.create_segment_to_index_task.create_segment_to_index_task
. tasks.deal_dataset_vector_index_task.deal_dataset_vector_index_task
. tasks.document_indexing_sync_task.document_indexing_sync_task
. tasks.document_indexing_task.document_indexing_task
. tasks.document_indexing_update_task.document_indexing_update_task
. tasks.enable_segment_to_index_task.enable_segment_to_index_task
. tasks.generate_conversation_summary_task.generate_conversation_summary_task
. tasks.mail_invite_member_task.send_invite_member_mail_task
. tasks.remove_document_from_index_task.remove_document_from_index_task
. tasks.remove_segment_from_index_task.remove_segment_from_index_task
. tasks.update_segment_index_task.update_segment_index_task
. tasks.update_segment_keyword_index_task.update_segment_keyword_index_task
[2023-07-31 12:58:08,831: INFO/MainProcess] Connected to redis://:**@localhost:6379/1
[2023-07-31 12:58:08,840: INFO/MainProcess] mingle: searching for neighbors
[2023-07-31 12:58:09,873: INFO/MainProcess] mingle: all alone
[2023-07-31 12:58:09,886: INFO/MainProcess] pidbox: Connected to redis://:**@localhost:6379/1.
[2023-07-31 12:58:09,890: INFO/MainProcess] celery@TAKATOST.lan ready.
```
***
### フロントエンドページデプロイ
Web フロントエンドクライアントページサービス
#### 基本環境インストール
Web フロントエンドサービスを起動するには[Node.js v18.x (LTS)](http://nodejs.org)、[NPMバージョン8.x.x](https://www.npmjs.com/)または[Yarn](https://yarnpkg.com/)が必要です。
* NodeJS + NPMをインストール
https://nodejs.org/en/download から対応するOSのv18.x以上のインストーラーをダウンロードしてインストールしてください。stableバージョンをお勧めします。NPMも同梱されています。
#### 起動手順
1. webディレクトリに移動
```
cd web
```
2. 依存関係をインストール
```
npm install
```
3. 環境変数を構成。現在のディレクトリに `.env.local` ファイルを作成し、`.env.example` の内容をコピーします。必要に応じてこれらの環境変数の値を変更します。
```
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# The deployment edition, SELF_HOSTED
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
# 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=
```
4. コードをビルド
```
npm run build
```
5. webサービスを開始
```
npm run start
# または
yarn start
# または
pnpm start
```
正常に起動すると、ターミナルに以下の情報が出力されます:
```
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
```
### Difyを訪問
最後に、http://127.0.0.1:3000 にアクセスすると、ローカルデプロイメントされたDifyを使用できます。
<end---/jp/getting-started/install-self-hosted/local-source-code.md---end>
<start---lang-check/zh_CN/getting-started/install-self-hosted/local-source-code.md---start>
# 本地源码启动
### 前置条件
> 安装 Dify 之前, 请确保你的机器已满足最低安装要求:
> - CPU >= 2 Core
> - RAM >= 4 GiB
| 操作系统 | 软件 | 说明 |
| -------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| macOS 10.14 or later | Docker Desktop | 将 Docker 虚拟机(VM)设置为使用至少 2 个虚拟 CPU(vCPU)和 8 GB 的初始内存。否则,安装可能会失败。有关更多信息,请参阅[在 Mac 上安装 Docker Desktop](https://docs.docker.com/desktop/mac/install/)。 |
| Linux platforms | <p>Docker 19.03 or later<br>Docker Compose 1.25.1 or later</p> | 请参阅[安装 Docker](https://docs.docker.com/engine/install/) 和[安装 Docker Compose](https://docs.docker.com/compose/install/) 以获取更多信息。 |
| Windows with WSL 2 enabled | Docker Desktop | 我们建议将源代码和其他数据绑定到 Linux 容器中时,将其存储在 Linux 文件系统中,而不是 Windows 文件系统中。有关更多信息,请参阅[使用 WSL 2 后端在 Windows 上安装 Docker Desktop](https://docs.docker.com/desktop/windows/install/#wsl-2-backend)。 |
> 若需要使用 OpenAI TTS,需要在系统中安装 FFmpeg 才可正常使用,详情可参考:[Link](https://docs.dify.ai/v/zh-hans/learn-more/faq/install-faq#id-15.-wen-ben-zhuan-yu-yin-yu-dao-zhe-ge-cuo-wu-zen-me-ban)。
Clone Dify 代码:
```Bash
git clone https://github.com/langgenius/dify.git
```
在启用业务服务之前,我们需要先部署 PostgreSQL / Redis / Weaviate(如果本地没有的话),可以通过以下命令启动:
```Bash
cd docker
cp middleware.env.example middleware.env
docker compose -f docker-compose.middleware.yaml up -d
```
***
### 服务端部署
* API 接口服务
* Worker 异步队列消费服务
#### 安装基础环境
服务器启动需要 Python 3.12。建议使用 [pyenv](https://github.com/pyenv/pyenv) 快速安装 Python 环境。
要安装其他 Python 版本,请使用 `pyenv install`。
```Bash
pyenv install 3.12
```
要切换到 "3.12" Python 环境,请使用以下命令:
```Bash
pyenv global 3.12
```
#### 启动步骤
1. 进入 api 目录
```
cd api
```
> macOS 系统可以通过 `brew install libmagic` 命令安装 libmagic.
2. 复制环境变量配置文件
```
cp .env.example .env
```
3. 生成随机密钥,并替换 `.env` 中 `SECRET_KEY` 的值
```
awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env
```
4. 安装依赖包
Dify API 服务使用 [Poetry](https://python-poetry.org/docs/) 来管理依赖。你可以执行 `poetry shell` 来激活环境。
```
poetry env use 3.12
poetry install
```
5. 执行数据库迁移
将数据库结构迁移至最新版本。
```
poetry shell
flask db upgrade
```
6. 启动 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
INFO:werkzeug:Press CTRL+C to quit
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 695-801-919
```
7. 启动 Worker 服务
用于消费异步队列任务,如知识库文件导入、更新知识库文档等异步操作。 Linux / MacOS 启动:
```
celery -A app.celery worker -P gevent -c 1 -Q dataset,generation,mail,ops_trace --loglevel INFO
```
如果使用 Windows 系统启动,请替换为该命令:
```
celery -A app.celery worker -P solo --without-gossip --without-mingle -Q dataset,generation,mail,ops_trace --loglevel INFO
```
正确输出:
```
-------------- celery@TAKATOST.lan v5.2.7 (dawn-chorus)
--- ***** -----
-- ******* ---- macOS-10.16-x86_64-i386-64bit 2023-07-31 12:58:08
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app: app:0x7fb568572a10
- ** ---------- .> transport: redis://:**@localhost:6379/1
- ** ---------- .> results: postgresql://postgres:**@localhost:5432/dify
- *** --- * --- .> concurrency: 1 (gevent)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> dataset exchange=dataset(direct) key=dataset
.> generation exchange=generation(direct) key=generation
.> mail exchange=mail(direct) key=mail
[tasks]
. tasks.add_document_to_index_task.add_document_to_index_task
. tasks.clean_dataset_task.clean_dataset_task
. tasks.clean_document_task.clean_document_task
. tasks.clean_notion_document_task.clean_notion_document_task
. tasks.create_segment_to_index_task.create_segment_to_index_task
. tasks.deal_dataset_vector_index_task.deal_dataset_vector_index_task
. tasks.document_indexing_sync_task.document_indexing_sync_task
. tasks.document_indexing_task.document_indexing_task
. tasks.document_indexing_update_task.document_indexing_update_task
. tasks.enable_segment_to_index_task.enable_segment_to_index_task
. tasks.generate_conversation_summary_task.generate_conversation_summary_task
. tasks.mail_invite_member_task.send_invite_member_mail_task
. tasks.remove_document_from_index_task.remove_document_from_index_task
. tasks.remove_segment_from_index_task.remove_segment_from_index_task
. tasks.update_segment_index_task.update_segment_index_task
. tasks.update_segment_keyword_index_task.update_segment_keyword_index_task
[2023-07-31 12:58:08,831: INFO/MainProcess] Connected to redis://:**@localhost:6379/1
[2023-07-31 12:58:08,840: INFO/MainProcess] mingle: searching for neighbors
[2023-07-31 12:58:09,873: INFO/MainProcess] mingle: all alone
[2023-07-31 12:58:09,886: INFO/MainProcess] pidbox: Connected to redis://:**@localhost:6379/1.
[2023-07-31 12:58:09,890: INFO/MainProcess] celery@TAKATOST.lan ready.
```
***
### 前端页面部署
Web 前端客户端页面服务
#### 安装基础环境
Web 前端服务启动需要用到 [Node.js v18.x (LTS)](http://nodejs.org) 、[NPM 版本 8.x.x ](https://www.npmjs.com/)或 [Yarn](https://yarnpkg.com/)。
* 安装 NodeJS + NPM
进入 https://nodejs.org/en/download,选择对应操作系统的 v18.x 以上的安装包下载并安装,建议 stable 版本,已自带 NPM。
#### 启动步骤
1. 进入 web 目录
```
cd web
```
2. 安装依赖包
```
npm install
```
3. 配置环境变量。在当前目录下创建文件 `.env.local`,并复制`.env.example`中的内容。根据需求修改这些环境变量的值:
```
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# The deployment edition, SELF_HOSTED
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
# 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=
```
4. 构建代码
```
npm run build
```
5. 启动 web 服务
```
npm run start
# or
yarn start
# or
pnpm start
```
正常启动后,终端会输出如下信息:
```
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
```
### 访问 Dify
最后,访问 http://127.0.0.1:3000 即可使用本地部署的 Dify。
<end---/zh_CN/getting-started/install-self-hosted/local-source-code.md---end>
@@ -59,6 +59,8 @@ pyenv global 3.12
```
cd api
```
> macOS 系统可以通过 `brew install libmagic` 命令安装 libmagic.
2. 复制环境变量配置文件
```