| # 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`. | ||||
| 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= | ||||
| 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 | ||||
| # ---------------------------- | # ---------------------------- | ||||
| def create_app(test_config=None) -> Flask: | |||||
| def create_app() -> Flask: | |||||
| app = DifyApp(__name__) | app = DifyApp(__name__) | ||||
| 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.config.from_object(Config()) | |||||
| app.secret_key = app.config['SECRET_KEY'] | app.secret_key = app.config['SECRET_KEY'] | ||||
| ), | ), | ||||
| 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'), | 
| 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', | ||||
| # ------------------------ | # ------------------------ | ||||
| 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') | ||||
| 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')) | ||||
| # ------------------------ | # ------------------------ | ||||
| # 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') | ||||
| 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') | 
| 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 | 
| # 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. | 
| ``` | ``` | ||||
| # 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. |