refactor: config file (#3852)

This commit is contained in:
takatost 2024-04-25 22:26:45 +08:00 committed by GitHub
parent 9cbb8ddd7f
commit 8bca908f15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 54 deletions

View File

@ -1,6 +1,3 @@
# Server Edition
EDITION=SELF_HOSTED
# Your App secret key will be used for securely signing the session cookie # 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. # 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`. # You can generate a strong key using `openssl rand -base64 42`.
@ -123,25 +120,6 @@ NOTION_CLIENT_SECRET=you-client-secret
NOTION_CLIENT_ID=you-client-id NOTION_CLIENT_ID=you-client-id
NOTION_INTERNAL_SECRET=you-internal-secret NOTION_INTERNAL_SECRET=you-internal-secret
# Hosted Model Credentials
HOSTED_OPENAI_API_KEY=
HOSTED_OPENAI_API_BASE=
HOSTED_OPENAI_API_ORGANIZATION=
HOSTED_OPENAI_TRIAL_ENABLED=false
HOSTED_OPENAI_QUOTA_LIMIT=200
HOSTED_OPENAI_PAID_ENABLED=false
HOSTED_AZURE_OPENAI_ENABLED=false
HOSTED_AZURE_OPENAI_API_KEY=
HOSTED_AZURE_OPENAI_API_BASE=
HOSTED_AZURE_OPENAI_QUOTA_LIMIT=200
HOSTED_ANTHROPIC_API_BASE=
HOSTED_ANTHROPIC_API_KEY=
HOSTED_ANTHROPIC_TRIAL_ENABLED=false
HOSTED_ANTHROPIC_QUOTA_LIMIT=600000
HOSTED_ANTHROPIC_PAID_ENABLED=false
ETL_TYPE=dify ETL_TYPE=dify
UNSTRUCTURED_API_URL= UNSTRUCTURED_API_URL=

View File

@ -1,28 +1,28 @@
import os import os
import sys
from logging.handlers import RotatingFileHandler
if not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != 'true': if not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != 'true':
from gevent import monkey from gevent import monkey
monkey.patch_all() monkey.patch_all()
# if os.environ.get("VECTOR_STORE") == 'milvus':
import grpc.experimental.gevent import grpc.experimental.gevent
grpc.experimental.gevent.init_gevent() grpc.experimental.gevent.init_gevent()
import json import json
import logging import logging
import sys
import threading import threading
import time import time
import warnings import warnings
from logging.handlers import RotatingFileHandler
from flask import Flask, Response, request from flask import Flask, Response, request
from flask_cors import CORS from flask_cors import CORS
from werkzeug.exceptions import Unauthorized from werkzeug.exceptions import Unauthorized
from commands import register_commands from commands import register_commands
from config import CloudEditionConfig, Config from config import Config
# DO NOT REMOVE BELOW # DO NOT REMOVE BELOW
from events import event_handlers from events import event_handlers
@ -75,16 +75,9 @@ config_type = os.getenv('EDITION', default='SELF_HOSTED') # ce edition first
# ---------------------------- # ----------------------------
def create_app(test_config=None) -> Flask: def create_app() -> Flask:
app = DifyApp(__name__) app = DifyApp(__name__)
app.config.from_object(Config())
if test_config:
app.config.from_object(test_config)
else:
if config_type == "CLOUD":
app.config.from_object(CloudEditionConfig())
else:
app.config.from_object(Config())
app.secret_key = app.config['SECRET_KEY'] app.secret_key = app.config['SECRET_KEY']
@ -101,6 +94,7 @@ def create_app(test_config=None) -> Flask:
), ),
logging.StreamHandler(sys.stdout) logging.StreamHandler(sys.stdout)
] ]
logging.basicConfig( logging.basicConfig(
level=app.config.get('LOG_LEVEL'), level=app.config.get('LOG_LEVEL'),
format=app.config.get('LOG_FORMAT'), format=app.config.get('LOG_FORMAT'),

View File

@ -5,6 +5,7 @@ import dotenv
dotenv.load_dotenv() dotenv.load_dotenv()
DEFAULTS = { DEFAULTS = {
'EDITION': 'SELF_HOSTED',
'DB_USERNAME': 'postgres', 'DB_USERNAME': 'postgres',
'DB_PASSWORD': '', 'DB_PASSWORD': '',
'DB_HOST': 'localhost', 'DB_HOST': 'localhost',
@ -106,7 +107,7 @@ class Config:
# ------------------------ # ------------------------
self.CURRENT_VERSION = "0.6.5" self.CURRENT_VERSION = "0.6.5"
self.COMMIT_SHA = get_env('COMMIT_SHA') self.COMMIT_SHA = get_env('COMMIT_SHA')
self.EDITION = "SELF_HOSTED" self.EDITION = get_env('EDITION')
self.DEPLOY_ENV = get_env('DEPLOY_ENV') self.DEPLOY_ENV = get_env('DEPLOY_ENV')
self.TESTING = False self.TESTING = False
self.LOG_LEVEL = get_env('LOG_LEVEL') self.LOG_LEVEL = get_env('LOG_LEVEL')
@ -260,7 +261,7 @@ class Config:
self.SMTP_USE_TLS = get_bool_env('SMTP_USE_TLS') self.SMTP_USE_TLS = get_bool_env('SMTP_USE_TLS')
# ------------------------ # ------------------------
# Workpace Configurations. # Workspace Configurations.
# ------------------------ # ------------------------
self.INVITE_EXPIRY_HOURS = int(get_env('INVITE_EXPIRY_HOURS')) self.INVITE_EXPIRY_HOURS = int(get_env('INVITE_EXPIRY_HOURS'))
@ -299,6 +300,12 @@ class Config:
# ------------------------ # ------------------------
# Platform Configurations. # Platform Configurations.
# ------------------------ # ------------------------
self.GITHUB_CLIENT_ID = get_env('GITHUB_CLIENT_ID')
self.GITHUB_CLIENT_SECRET = get_env('GITHUB_CLIENT_SECRET')
self.GOOGLE_CLIENT_ID = get_env('GOOGLE_CLIENT_ID')
self.GOOGLE_CLIENT_SECRET = get_env('GOOGLE_CLIENT_SECRET')
self.OAUTH_REDIRECT_PATH = get_env('OAUTH_REDIRECT_PATH')
self.HOSTED_OPENAI_API_KEY = get_env('HOSTED_OPENAI_API_KEY') self.HOSTED_OPENAI_API_KEY = get_env('HOSTED_OPENAI_API_KEY')
self.HOSTED_OPENAI_API_BASE = get_env('HOSTED_OPENAI_API_BASE') self.HOSTED_OPENAI_API_BASE = get_env('HOSTED_OPENAI_API_BASE')
self.HOSTED_OPENAI_API_ORGANIZATION = get_env('HOSTED_OPENAI_API_ORGANIZATION') self.HOSTED_OPENAI_API_ORGANIZATION = get_env('HOSTED_OPENAI_API_ORGANIZATION')
@ -345,17 +352,3 @@ class Config:
self.KEYWORD_DATA_SOURCE_TYPE = get_env('KEYWORD_DATA_SOURCE_TYPE') self.KEYWORD_DATA_SOURCE_TYPE = get_env('KEYWORD_DATA_SOURCE_TYPE')
self.ENTERPRISE_ENABLED = get_bool_env('ENTERPRISE_ENABLED') self.ENTERPRISE_ENABLED = get_bool_env('ENTERPRISE_ENABLED')
class CloudEditionConfig(Config):
def __init__(self):
super().__init__()
self.EDITION = "CLOUD"
self.GITHUB_CLIENT_ID = get_env('GITHUB_CLIENT_ID')
self.GITHUB_CLIENT_SECRET = get_env('GITHUB_CLIENT_SECRET')
self.GOOGLE_CLIENT_ID = get_env('GOOGLE_CLIENT_ID')
self.GOOGLE_CLIENT_SECRET = get_env('GOOGLE_CLIENT_SECRET')
self.OAUTH_REDIRECT_PATH = get_env('OAUTH_REDIRECT_PATH')

View File

@ -247,7 +247,6 @@ services:
image: langgenius/dify-web:0.6.5 image: langgenius/dify-web:0.6.5
restart: always restart: always
environment: environment:
EDITION: SELF_HOSTED
# The base URL of console application api server, refers to the Console base URL of WEB service if console domain is # The base URL of console application api server, refers to the Console base URL of WEB service if console domain is
# different from api or web app domain. # different from api or web app domain.
# example: http://cloud.dify.ai # example: http://cloud.dify.ai

View File

@ -1,6 +1,6 @@
# For production release, change this to PRODUCTION # For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# The deployment edition, SELF_HOSTED or CLOUD # The deployment edition, SELF_HOSTED
NEXT_PUBLIC_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 # 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. # different from api or web app domain.

View File

@ -17,7 +17,7 @@ Then, configure the environment variables. Create a file named `.env.local` in t
``` ```
# For production release, change this to PRODUCTION # For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# The deployment edition, SELF_HOSTED or CLOUD # The deployment edition, SELF_HOSTED
NEXT_PUBLIC_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 # 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. # different from api or web app domain.