Skip to content

Commit

Permalink
refactor: Create a dify_config with Pydantic. (#5938)
Browse files Browse the repository at this point in the history
  • Loading branch information
laipz8200 authored Jul 3, 2024
1 parent c490bdf commit cb8feb7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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':
from gevent import monkey
Expand Down Expand Up @@ -81,7 +81,7 @@ def create_flask_app_with_configs() -> Flask:
with configs loaded from .env file
"""
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
for key, value in dify_app.config.items():
Expand Down
3 changes: 2 additions & 1 deletion api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask import current_app
from werkzeug.exceptions import NotFound

from configs import dify_config
from constants.languages import languages
from core.rag.datasource.vdb.vector_factory import Vector
from core.rag.datasource.vdb.vector_type import VectorType
Expand Down Expand Up @@ -112,7 +113,7 @@ def reset_encrypt_key_pair():
After the reset, all LLM credentials will become invalid, requiring re-entry.
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'))
return

Expand Down
4 changes: 4 additions & 0 deletions api/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

from .app_config import DifyConfig

dify_config = DifyConfig()

0 comments on commit cb8feb7

Please sign in to comment.