dify Start with Local Source Code

Server Deployment

  • API Interface Service

  • Worker Asynchronous Queue Consumption Service

Installation of the basic environment:

Server startup requires Python 3.10.x. It is recommended to use pyenv for quick installation of the Python environment.

To install additional Python versions, use pyenv install.

pyenv install 3.10

To switch to the "3.10" Python environment, use the following command:

pyenv global 3.10

Follow these steps :

  1. Navigate to the "api" directory:

  • cd api
  • Copy the environment variable configuration file:

  • cp .env.example .env
  • Generate a random secret key and replace the value of SECRET_KEY in the .env file:

  • SECRET_KEY=$(openssl rand -base64 42)
    ESCAPED_SECRET_KEY=$(printf '%s\n' "$SECRET_KEY" | sed 's/[\/&]/\\&/g')
    sed -i "s/SECRET_KEY=.*/SECRET_KEY=${ESCAPED_SECRET_KEY}/" .env
    
  • Install the required dependencies:

    Dify API service uses Poetry to manage dependencies. You can execute poetry shell to activate the environment.

  • poetry env use 3.10
    poetry install
  • Perform the database migration

    Perform database migration to the latest version:

  • poetry shell
    flask db upgrade
  • 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
  • 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:

  1.  -------------- 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) and NPM version 8.x.x or Yarn.

  • Install NodeJS + NPM

Please visit 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
  • Install the dependencies.

  • npm install
  • 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=
  • Build the code

  • npm run build
  • Start the web service:

  1. 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 to use the locally deployed Dify.

SECRET_KEY=$(openssl rand -base64 42)
sed -i "s/SECRET_KEY=.*/SECRET_KEY=${SECRET_KEY}/" .env

要安装最新版本的 Poetry,你可以按照以下步骤进行。Poetry 提供了一种简单的方法来安装和管理其版本。
1. 安装或更新 Poetry
你可以使用以下命令来安装或更新 Poetry:
curl -sSL https://install.python-poetry.org | python3 -


          
2. 配置环境变量
安装完成后,你需要将 Poetry 的路径添加到你的环境变量中。通常情况下,安装脚本会自动完成这一步。如果没有,你可以手动添加。
编辑你的 ~/.bashrc(或 ~/.zshrc,如果你使用的是 Zsh)文件:
nano ~/.bashrc
          
添加以下行:
export PATH="$HOME/.local/bin:$PATH"
          
保存并退出编辑器,然后重新加载 shell 配置:
source ~/.bashrc
          
3. 验证安装
你可以通过以下命令验证 Poetry 是否已正确安装:
poetry --version
          
这应该会输出 Poetry 的版本号,例如:
Poetry version 1.3.2
      
4. 使用 Poetry 管理环境
现在你可以使用 Poetry 来管理你的项目环境。例如,使用以下命令来创建和管理 Python 3.10 环境:
poetry env use 3.10
poetry install
          
总结
通过上述步骤,你应该能够成功安装和配置最新版本的 Poetry。如果你在任何步骤中遇到问题或需要进一步的帮助,请告诉我!

curl -sSL https://install.python-poetry.org | python3 -

### Dify 凭证验证失败 (Status Code 404) 的解决方案 当遇到 `An error occurred during credentials validation: API request failed with status code 404` 错误时,通常表示请求的资源未找到。具体到此错误中的提示 `{“error”:“model “abc” not found, try pulling it first”}`[^4],可以推测问题可能源于指定的模型名称不正确或者该模型尚未被加载。 以下是针对此类问题的具体解决方法: #### 1. 验证模型名称 确认配置文件或代码中使用的模型名称是否正确。如果模型名设置为 `"abc"` 或其他不存在的名字,则需要将其替换为实际支持的模型名称。例如,在使用 OpenRouter 提供的服务时,应查阅官方文档获取可用模型列表并更新配置。 ```python config = { 'model': 'deepseek-v3-free', # 替换为正确的模型名称 } ``` #### 2. 下载缺失模型 某些情况下,即使指定了有效的模型名称,仍需手动下载对应模型才能正常运行程序。按照错误消息建议尝试执行拉取操作来完成这一过程: ```bash dify pull deepseek-v3-free ``` 上述命令假设存在名为 `dify` 的 CLI 工具用于管理相关依赖项;如果没有这样的工具,请参照项目文档了解如何通过其他方式同步所需资产。 #### 3. 检查网络连接状态 由于 HTTP 状态码 404 表明服务器端未能定位所请求的内容,因此还需要考虑是否存在临时性的网络中断影响到了数据传输环节。确保设备具备稳定互联网接入能力后再重试先前的操作步骤。 #### 4. 更新 SDK 版本 如果以上措施均无法解决问题,可能是当前安装版本过旧而导致兼容性冲突所致。此时应当升级至最新版SDK以获得更好的功能支持以及修复已知漏洞的能力。 ```bash pip install --upgrade dify-sdk openrouter-python ``` --- ### 总结 综上所述,处理 Dify 中出现的 `Credentials validation failed with status code 404` 主要涉及以下几个方面的工作:校正参数设定、补充必要组件、优化外部条件以及适时调整技术栈构成部分。只有全面排查各个环节潜在隐患之后才能够彻底消除这类异常现象的发生几率。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunnf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值