Browse Source

refactor: Create a `dify_config` with Pydantic. (#5938)

tags/0.6.13
-LAN- 1 year ago
parent
commit
cb8feb732f
No account linked to committer's email address
3 changed files with 8 additions and 3 deletions
  1. 2
    2
      api/app.py
  2. 2
    1
      api/commands.py
  3. 4
    0
      api/configs/__init__.py

+ 2
- 2
api/app.py View File

import os import os


from configs.app_config import DifyConfig
from configs import dify_config


if not os.environ.get("DEBUG") or os.environ.get("DEBUG", "false").lower() != 'true': if not os.environ.get("DEBUG") or os.environ.get("DEBUG", "false").lower() != 'true':
from gevent import monkey from gevent import monkey
with configs loaded from .env file with configs loaded from .env file
""" """
dify_app = DifyApp(__name__) dify_app = DifyApp(__name__)
dify_app.config.from_mapping(DifyConfig().model_dump())
dify_app.config.from_mapping(dify_config.model_dump())


# populate configs into system environment variables # populate configs into system environment variables
for key, value in dify_app.config.items(): for key, value in dify_app.config.items():

+ 2
- 1
api/commands.py View File

from flask import current_app from flask import current_app
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound


from configs import dify_config
from constants.languages import languages from constants.languages import languages
from core.rag.datasource.vdb.vector_factory import Vector from core.rag.datasource.vdb.vector_factory import Vector
from core.rag.datasource.vdb.vector_type import VectorType from core.rag.datasource.vdb.vector_type import VectorType
After the reset, all LLM credentials will become invalid, requiring re-entry. After the reset, all LLM credentials will become invalid, requiring re-entry.
Only support SELF_HOSTED mode. Only support SELF_HOSTED mode.
""" """
if current_app.config['EDITION'] != 'SELF_HOSTED':
if dify_config.EDITION != 'SELF_HOSTED':
click.echo(click.style('Sorry, only support SELF_HOSTED mode.', fg='red')) click.echo(click.style('Sorry, only support SELF_HOSTED mode.', fg='red'))
return return



+ 4
- 0
api/configs/__init__.py View File


from .app_config import DifyConfig

dify_config = DifyConfig()

Loading…
Cancel
Save