From ce492d13f1103ede305a01cfd3feee8ffecdea8d Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 17 May 2023 14:53:15 +0800 Subject: [PATCH 1/7] feat: gpt4 max token set to 8k (#67) --- .../app/configuration/config-model/index.tsx | 13 ++++++++++++- web/i18n/lang/common.en.ts | 1 + web/i18n/lang/common.zh.ts | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/web/app/components/app/configuration/config-model/index.tsx b/web/app/components/app/configuration/config-model/index.tsx index 999e989682..a4f7b6a636 100644 --- a/web/app/components/app/configuration/config-model/index.tsx +++ b/web/app/components/app/configuration/config-model/index.tsx @@ -11,6 +11,7 @@ import type { CompletionParams } from '@/models/debug' import { Cog8ToothIcon, InformationCircleIcon, ChevronDownIcon } from '@heroicons/react/24/outline' import { AppType } from '@/types/app' import { TONE_LIST } from '@/config' +import Toast from '@/app/components/base/toast' export type IConifgModelProps = { mode: string @@ -93,7 +94,7 @@ const ConifgModel: FC = ({ key: 'max_tokens', tip: t('common.model.params.maxTokenTip'), step: 100, - max: 4000, + max: modelId === 'gpt-4' ? 8000 : 4000, }, ] @@ -114,6 +115,16 @@ const ConifgModel: FC = ({ onShowUseGPT4Confirm() return } + if(id !== 'gpt-4' && completionParams.max_tokens > 4000) { + Toast.notify({ + type: 'warning', + message: t('common.model.params.setToCurrentModelMaxTokenTip') + }) + onCompletionParamsChange({ + ...completionParams, + max_tokens: 4000 + }) + } setModelId(id) } } diff --git a/web/i18n/lang/common.en.ts b/web/i18n/lang/common.en.ts index 6771cbc42c..f0106477c2 100644 --- a/web/i18n/lang/common.en.ts +++ b/web/i18n/lang/common.en.ts @@ -50,6 +50,7 @@ const translation = { maxToken: 'Max token', maxTokenTip: 'Max tokens generated is 2,048 or 4,000, depending on the model. Prompt and completion share this limit. One token is roughly 1 English character.', + setToCurrentModelMaxTokenTip: 'Max token is updated to the maximum token of the current model 4,000.', }, tone: { Creative: 'Creative', diff --git a/web/i18n/lang/common.zh.ts b/web/i18n/lang/common.zh.ts index a2f03a1bc1..f96bdfa89d 100644 --- a/web/i18n/lang/common.zh.ts +++ b/web/i18n/lang/common.zh.ts @@ -50,6 +50,7 @@ const translation = { maxToken: '最大 Token', maxTokenTip: '生成的最大令牌数为 2,048 或 4,000,取决于模型。提示和完成共享令牌数限制。一个令牌约等于 1 个英文或 4 个中文字符。', + setToCurrentModelMaxTokenTip: '最大令牌数更新为当前模型最大的令牌数 4,000。', }, tone: { Creative: '创意', From 0587ff0fba3ac73c2bbdd8a84c7fe81103ab12ed Mon Sep 17 00:00:00 2001 From: John Wang Date: Wed, 17 May 2023 15:02:58 +0800 Subject: [PATCH 2/7] fix: remove empty segment in splitter (#68) --- api/core/indexing_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/indexing_runner.py b/api/core/indexing_runner.py index f06f3a0034..a4ff9ed287 100644 --- a/api/core/indexing_runner.py +++ b/api/core/indexing_runner.py @@ -343,7 +343,7 @@ class IndexingRunner: # parse document to nodes nodes = node_parser.get_nodes_from_documents([text_doc]) - + nodes = [node for node in nodes if node.text is not None and node.text.strip()] all_nodes.extend(nodes) return all_nodes From f8eefa31fef49f96e790c27c0fbf4c1ec7355f8d Mon Sep 17 00:00:00 2001 From: Yuhao Date: Wed, 17 May 2023 15:40:21 +0800 Subject: [PATCH 3/7] feat: add redis ssl support (#65) --- api/config.py | 7 +++++++ api/extensions/ext_celery.py | 15 +++++++++++++++ api/extensions/ext_redis.py | 9 +++++++-- api/extensions/ext_session.py | 8 +++++++- docker/docker-compose.yaml | 6 ++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/api/config.py b/api/config.py index 04c44f2447..36fcb3450f 100644 --- a/api/config.py +++ b/api/config.py @@ -21,9 +21,11 @@ DEFAULTS = { 'REDIS_HOST': 'localhost', 'REDIS_PORT': '6379', 'REDIS_DB': '0', + 'REDIS_USE_SSL': 'False', 'SESSION_REDIS_HOST': 'localhost', 'SESSION_REDIS_PORT': '6379', 'SESSION_REDIS_DB': '2', + 'SESSION_REDIS_USE_SSL': 'False', 'OAUTH_REDIRECT_PATH': '/console/api/oauth/authorize', 'OAUTH_REDIRECT_INDEX_PATH': '/', 'CONSOLE_URL': 'https://cloud.dify.ai', @@ -105,14 +107,18 @@ class Config: # redis settings self.REDIS_HOST = get_env('REDIS_HOST') self.REDIS_PORT = get_env('REDIS_PORT') + self.REDIS_USERNAME = get_env('REDIS_USERNAME') self.REDIS_PASSWORD = get_env('REDIS_PASSWORD') self.REDIS_DB = get_env('REDIS_DB') + self.REDIS_USE_SSL = get_bool_env('REDIS_USE_SSL') # session redis settings self.SESSION_REDIS_HOST = get_env('SESSION_REDIS_HOST') self.SESSION_REDIS_PORT = get_env('SESSION_REDIS_PORT') + self.SESSION_REDIS_USERNAME = get_env('SESSION_REDIS_USERNAME') self.SESSION_REDIS_PASSWORD = get_env('SESSION_REDIS_PASSWORD') self.SESSION_REDIS_DB = get_env('SESSION_REDIS_DB') + self.SESSION_REDIS_USE_SSL = get_bool_env('SESSION_REDIS_USE_SSL') # storage settings self.STORAGE_TYPE = get_env('STORAGE_TYPE') @@ -165,6 +171,7 @@ class Config: self.CELERY_BACKEND = get_env('CELERY_BACKEND') self.CELERY_RESULT_BACKEND = 'db+{}'.format(self.SQLALCHEMY_DATABASE_URI) \ if self.CELERY_BACKEND == 'database' else self.CELERY_BROKER_URL + self.BROKER_USE_SSL = self.CELERY_BROKER_URL.startswith('rediss://') # hosted provider credentials self.OPENAI_API_KEY = get_env('OPENAI_API_KEY') diff --git a/api/extensions/ext_celery.py b/api/extensions/ext_celery.py index f738b984d9..5750d77dba 100644 --- a/api/extensions/ext_celery.py +++ b/api/extensions/ext_celery.py @@ -15,9 +15,24 @@ def init_app(app: Flask) -> Celery: backend=app.config["CELERY_BACKEND"], task_ignore_result=True, ) + + # Add SSL options to the Celery configuration + ssl_options = { + "ssl_cert_reqs": None, + "ssl_ca_certs": None, + "ssl_certfile": None, + "ssl_keyfile": None, + } + celery_app.conf.update( result_backend=app.config["CELERY_RESULT_BACKEND"], ) + + if app.config["BROKER_USE_SSL"]: + celery_app.conf.update( + broker_use_ssl=ssl_options, # Add the SSL options to the broker configuration + ) + celery_app.set_default() app.extensions["celery"] = celery_app return celery_app diff --git a/api/extensions/ext_redis.py b/api/extensions/ext_redis.py index c3e021e798..f00b300808 100644 --- a/api/extensions/ext_redis.py +++ b/api/extensions/ext_redis.py @@ -1,18 +1,23 @@ import redis - +from redis.connection import SSLConnection, Connection redis_client = redis.Redis() def init_app(app): + connection_class = Connection + if app.config.get('REDIS_USE_SSL', False): + connection_class = SSLConnection + redis_client.connection_pool = redis.ConnectionPool(**{ 'host': app.config.get('REDIS_HOST', 'localhost'), 'port': app.config.get('REDIS_PORT', 6379), + 'username': app.config.get('REDIS_USERNAME', None), 'password': app.config.get('REDIS_PASSWORD', None), 'db': app.config.get('REDIS_DB', 0), 'encoding': 'utf-8', 'encoding_errors': 'strict', 'decode_responses': False - }) + }, connection_class=connection_class) app.extensions['redis'] = redis_client diff --git a/api/extensions/ext_session.py b/api/extensions/ext_session.py index 5b454d469e..e03a22b0c8 100644 --- a/api/extensions/ext_session.py +++ b/api/extensions/ext_session.py @@ -1,4 +1,5 @@ import redis +from redis.connection import SSLConnection, Connection from flask import request from flask_session import Session, SqlAlchemySessionInterface, RedisSessionInterface from flask_session.sessions import total_seconds @@ -23,16 +24,21 @@ def init_app(app): if session_type == 'sqlalchemy': app.session_interface = sqlalchemy_session_interface elif session_type == 'redis': + connection_class = Connection + if app.config.get('SESSION_REDIS_USE_SSL', False): + connection_class = SSLConnection + sess_redis_client = redis.Redis() sess_redis_client.connection_pool = redis.ConnectionPool(**{ 'host': app.config.get('SESSION_REDIS_HOST', 'localhost'), 'port': app.config.get('SESSION_REDIS_PORT', 6379), + 'username': app.config.get('SESSION_REDIS_USERNAME', None), 'password': app.config.get('SESSION_REDIS_PASSWORD', None), 'db': app.config.get('SESSION_REDIS_DB', 2), 'encoding': 'utf-8', 'encoding_errors': 'strict', 'decode_responses': False - }) + }, connection_class=connection_class) app.extensions['session_redis'] = sess_redis_client diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index a337377cfa..04728184b3 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -36,14 +36,18 @@ services: # It is consistent with the configuration in the 'redis' service below. REDIS_HOST: redis REDIS_PORT: 6379 + REDIS_USERNAME: '' REDIS_PASSWORD: difyai123456 + REDIS_USE_SSL: 'false' # use redis db 0 for redis cache REDIS_DB: 0 # The configurations of session, Supported values are `sqlalchemy`. `redis` SESSION_TYPE: redis SESSION_REDIS_HOST: redis SESSION_REDIS_PORT: 6379 + SESSION_REDIS_USERNAME: '' SESSION_REDIS_PASSWORD: difyai123456 + SESSION_REDIS_USE_SSL: 'false' # use redis db 2 for session store SESSION_REDIS_DB: 2 # The configurations of celery broker. @@ -129,8 +133,10 @@ services: # The configurations of redis cache connection. REDIS_HOST: redis REDIS_PORT: 6379 + REDIS_USERNAME: '' REDIS_PASSWORD: difyai123456 REDIS_DB: 0 + REDIS_USE_SSL: 'false' # The configurations of celery broker. CELERY_BROKER_URL: redis://:difyai123456@redis:6379/1 # The type of storage to use for storing user files. Supported values are `local` and `s3`, Default: `local` From 15f932573a066fdd94e507709f6087b0ae7bb5f2 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Wed, 17 May 2023 19:05:51 +0800 Subject: [PATCH 4/7] fix: settings modal (#74) --- web/app/components/base/modal/index.tsx | 4 +++- web/app/components/header/account-setting/index.tsx | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/web/app/components/base/modal/index.tsx b/web/app/components/base/modal/index.tsx index bc33ac8e0a..05ec019aa6 100644 --- a/web/app/components/base/modal/index.tsx +++ b/web/app/components/base/modal/index.tsx @@ -5,6 +5,7 @@ import { XMarkIcon } from '@heroicons/react/24/outline' type IModal = { className?: string + wrapperClassName?: string isShow: boolean onClose: () => void title?: React.ReactNode @@ -15,6 +16,7 @@ type IModal = { export default function Modal({ className, + wrapperClassName, isShow, onClose, title, @@ -38,7 +40,7 @@ export default function Modal({
-
+
{ }} className={s.modal} + wrapperClassName='pt-[60px]' >
From a4481a3f29a843a955cb4ad69b70a29c2e9448e5 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 17 May 2023 21:50:42 +0800 Subject: [PATCH 5/7] fix: prompt no blank too long break ui (#81) --- .../components/app/configuration/prompt-value-panel/index.tsx | 2 +- web/app/components/base/block-input/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/app/components/app/configuration/prompt-value-panel/index.tsx b/web/app/components/app/configuration/prompt-value-panel/index.tsx index b86094556c..e5884bf3fb 100644 --- a/web/app/components/app/configuration/prompt-value-panel/index.tsx +++ b/web/app/components/app/configuration/prompt-value-panel/index.tsx @@ -73,7 +73,7 @@ const PromptValuePanel: FC = ({ { (promptTemplate && promptTemplate?.trim()) ? (
= ({ }, [isEditing]) const style = classNames({ - 'block px-4 py-1 w-full h-full text-sm text-gray-900 outline-0 border-0': true, + 'block px-4 py-1 w-full h-full text-sm text-gray-900 outline-0 border-0 break-all': true, 'block-input--editing': isEditing, }) From ac2a1bc9549b4e5d2939e61b86a174e950dd5799 Mon Sep 17 00:00:00 2001 From: GarfieldLucy <1020462958@qq.com> Date: Thu, 18 May 2023 00:11:17 +0800 Subject: [PATCH 6/7] fix: chat log overflow style upgrade (#87) Co-authored-by: llx_changed --- web/app/components/app/log/list.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app/components/app/log/list.tsx b/web/app/components/app/log/list.tsx index e29eafa6f0..4fb7a13b25 100644 --- a/web/app/components/app/log/list.tsx +++ b/web/app/components/app/log/list.tsx @@ -166,7 +166,7 @@ function DetailPanel + return (
{/* Panel Header */}
@@ -207,7 +207,7 @@ function DetailPanel{detail.model_config?.pre_prompt || emptyText}
{!isChatMode - ?
+ ?
: items.length < 8 - ?
+ ?
Date: Thu, 18 May 2023 08:25:37 +0800 Subject: [PATCH 7/7] add a config to disable provider config validation (#85) --- api/config.py | 4 ++++ api/services/provider_service.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/api/config.py b/api/config.py index 36fcb3450f..1e6000c8ae 100644 --- a/api/config.py +++ b/api/config.py @@ -46,6 +46,7 @@ DEFAULTS = { 'CELERY_BACKEND': 'database', 'PDF_PREVIEW': 'True', 'LOG_LEVEL': 'INFO', + 'DISABLE_PROVIDER_CONFIG_VALIDATION': 'False', } @@ -176,6 +177,9 @@ class Config: # hosted provider credentials self.OPENAI_API_KEY = get_env('OPENAI_API_KEY') + # By default it is False + # You could disable it for compatibility with certain OpenAPI providers + self.DISABLE_PROVIDER_CONFIG_VALIDATION = get_bool_env('DISABLE_PROVIDER_CONFIG_VALIDATION') class CloudEditionConfig(Config): diff --git a/api/services/provider_service.py b/api/services/provider_service.py index 7f6c7c9303..39ee8353c0 100644 --- a/api/services/provider_service.py +++ b/api/services/provider_service.py @@ -62,6 +62,8 @@ class ProviderService: @staticmethod def validate_provider_configs(tenant, provider_name: ProviderName, configs: Union[dict | str]): + if current_app.config['DISABLE_PROVIDER_CONFIG_VALIDATION']: + return llm_provider_service = LLMProviderService(tenant.id, provider_name.value) return llm_provider_service.config_validate(configs)