Skip to content

Commit 8bca908

Browse files
authored
refactor: config file (langgenius#3852)
1 parent 9cbb8dd commit 8bca908

File tree

6 files changed

+18
-54
lines changed

6 files changed

+18
-54
lines changed

api/.env.example

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Server Edition
2-
EDITION=SELF_HOSTED
3-
41
# Your App secret key will be used for securely signing the session cookie
52
# Make sure you are changing this key for your deployment with a strong key.
63
# You can generate a strong key using `openssl rand -base64 42`.
@@ -123,25 +120,6 @@ NOTION_CLIENT_SECRET=you-client-secret
123120
NOTION_CLIENT_ID=you-client-id
124121
NOTION_INTERNAL_SECRET=you-internal-secret
125122

126-
# Hosted Model Credentials
127-
HOSTED_OPENAI_API_KEY=
128-
HOSTED_OPENAI_API_BASE=
129-
HOSTED_OPENAI_API_ORGANIZATION=
130-
HOSTED_OPENAI_TRIAL_ENABLED=false
131-
HOSTED_OPENAI_QUOTA_LIMIT=200
132-
HOSTED_OPENAI_PAID_ENABLED=false
133-
134-
HOSTED_AZURE_OPENAI_ENABLED=false
135-
HOSTED_AZURE_OPENAI_API_KEY=
136-
HOSTED_AZURE_OPENAI_API_BASE=
137-
HOSTED_AZURE_OPENAI_QUOTA_LIMIT=200
138-
139-
HOSTED_ANTHROPIC_API_BASE=
140-
HOSTED_ANTHROPIC_API_KEY=
141-
HOSTED_ANTHROPIC_TRIAL_ENABLED=false
142-
HOSTED_ANTHROPIC_QUOTA_LIMIT=600000
143-
HOSTED_ANTHROPIC_PAID_ENABLED=false
144-
145123
ETL_TYPE=dify
146124
UNSTRUCTURED_API_URL=
147125

api/app.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import os
2-
import sys
3-
from logging.handlers import RotatingFileHandler
42

53
if not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != 'true':
64
from gevent import monkey
75

86
monkey.patch_all()
9-
# if os.environ.get("VECTOR_STORE") == 'milvus':
7+
108
import grpc.experimental.gevent
119

1210
grpc.experimental.gevent.init_gevent()
1311

1412
import json
1513
import logging
14+
import sys
1615
import threading
1716
import time
1817
import warnings
18+
from logging.handlers import RotatingFileHandler
1919

2020
from flask import Flask, Response, request
2121
from flask_cors import CORS
2222
from werkzeug.exceptions import Unauthorized
2323

2424
from commands import register_commands
25-
from config import CloudEditionConfig, Config
25+
from config import Config
2626

2727
# DO NOT REMOVE BELOW
2828
from events import event_handlers
@@ -75,16 +75,9 @@ class DifyApp(Flask):
7575
# ----------------------------
7676

7777

78-
def create_app(test_config=None) -> Flask:
78+
def create_app() -> Flask:
7979
app = DifyApp(__name__)
80-
81-
if test_config:
82-
app.config.from_object(test_config)
83-
else:
84-
if config_type == "CLOUD":
85-
app.config.from_object(CloudEditionConfig())
86-
else:
87-
app.config.from_object(Config())
80+
app.config.from_object(Config())
8881

8982
app.secret_key = app.config['SECRET_KEY']
9083

@@ -101,6 +94,7 @@ def create_app(test_config=None) -> Flask:
10194
),
10295
logging.StreamHandler(sys.stdout)
10396
]
97+
10498
logging.basicConfig(
10599
level=app.config.get('LOG_LEVEL'),
106100
format=app.config.get('LOG_FORMAT'),

api/config.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
dotenv.load_dotenv()
66

77
DEFAULTS = {
8+
'EDITION': 'SELF_HOSTED',
89
'DB_USERNAME': 'postgres',
910
'DB_PASSWORD': '',
1011
'DB_HOST': 'localhost',
@@ -106,7 +107,7 @@ def __init__(self):
106107
# ------------------------
107108
self.CURRENT_VERSION = "0.6.5"
108109
self.COMMIT_SHA = get_env('COMMIT_SHA')
109-
self.EDITION = "SELF_HOSTED"
110+
self.EDITION = get_env('EDITION')
110111
self.DEPLOY_ENV = get_env('DEPLOY_ENV')
111112
self.TESTING = False
112113
self.LOG_LEVEL = get_env('LOG_LEVEL')
@@ -260,7 +261,7 @@ def __init__(self):
260261
self.SMTP_USE_TLS = get_bool_env('SMTP_USE_TLS')
261262

262263
# ------------------------
263-
# Workpace Configurations.
264+
# Workspace Configurations.
264265
# ------------------------
265266
self.INVITE_EXPIRY_HOURS = int(get_env('INVITE_EXPIRY_HOURS'))
266267

@@ -299,6 +300,12 @@ def __init__(self):
299300
# ------------------------
300301
# Platform Configurations.
301302
# ------------------------
303+
self.GITHUB_CLIENT_ID = get_env('GITHUB_CLIENT_ID')
304+
self.GITHUB_CLIENT_SECRET = get_env('GITHUB_CLIENT_SECRET')
305+
self.GOOGLE_CLIENT_ID = get_env('GOOGLE_CLIENT_ID')
306+
self.GOOGLE_CLIENT_SECRET = get_env('GOOGLE_CLIENT_SECRET')
307+
self.OAUTH_REDIRECT_PATH = get_env('OAUTH_REDIRECT_PATH')
308+
302309
self.HOSTED_OPENAI_API_KEY = get_env('HOSTED_OPENAI_API_KEY')
303310
self.HOSTED_OPENAI_API_BASE = get_env('HOSTED_OPENAI_API_BASE')
304311
self.HOSTED_OPENAI_API_ORGANIZATION = get_env('HOSTED_OPENAI_API_ORGANIZATION')
@@ -345,17 +352,3 @@ def __init__(self):
345352

346353
self.KEYWORD_DATA_SOURCE_TYPE = get_env('KEYWORD_DATA_SOURCE_TYPE')
347354
self.ENTERPRISE_ENABLED = get_bool_env('ENTERPRISE_ENABLED')
348-
349-
350-
class CloudEditionConfig(Config):
351-
352-
def __init__(self):
353-
super().__init__()
354-
355-
self.EDITION = "CLOUD"
356-
357-
self.GITHUB_CLIENT_ID = get_env('GITHUB_CLIENT_ID')
358-
self.GITHUB_CLIENT_SECRET = get_env('GITHUB_CLIENT_SECRET')
359-
self.GOOGLE_CLIENT_ID = get_env('GOOGLE_CLIENT_ID')
360-
self.GOOGLE_CLIENT_SECRET = get_env('GOOGLE_CLIENT_SECRET')
361-
self.OAUTH_REDIRECT_PATH = get_env('OAUTH_REDIRECT_PATH')

docker/docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ services:
247247
image: langgenius/dify-web:0.6.5
248248
restart: always
249249
environment:
250-
EDITION: SELF_HOSTED
251250
# The base URL of console application api server, refers to the Console base URL of WEB service if console domain is
252251
# different from api or web app domain.
253252
# example: http://cloud.dify.ai

web/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# For production release, change this to PRODUCTION
22
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
3-
# The deployment edition, SELF_HOSTED or CLOUD
3+
# The deployment edition, SELF_HOSTED
44
NEXT_PUBLIC_EDITION=SELF_HOSTED
55
# The base URL of console application, refers to the Console base URL of WEB service if console domain is
66
# different from api or web app domain.

web/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Then, configure the environment variables. Create a file named `.env.local` in t
1717
```
1818
# For production release, change this to PRODUCTION
1919
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
20-
# The deployment edition, SELF_HOSTED or CLOUD
20+
# The deployment edition, SELF_HOSTED
2121
NEXT_PUBLIC_EDITION=SELF_HOSTED
2222
# The base URL of console application, refers to the Console base URL of WEB service if console domain is
2323
# different from api or web app domain.

0 commit comments

Comments
 (0)