From a98284b1ef2fb0081cb96670da79470d9c9f9aa2 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 30 Jul 2024 11:15:26 +0800 Subject: [PATCH 01/19] refactor(api): Switch to `dify_config` (#6750) Signed-off-by: -LAN- --- api/commands.py | 18 +++++++++--------- api/controllers/console/auth/login.py | 4 ++-- api/core/indexing_runner.py | 5 +++-- api/core/rag/datasource/keyword/jieba/jieba.py | 4 ++-- api/libs/passport.py | 9 +++++---- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/api/commands.py b/api/commands.py index 6719539cc8..c7ffb47b51 100644 --- a/api/commands.py +++ b/api/commands.py @@ -249,8 +249,7 @@ def migrate_knowledge_vector_database(): create_count = 0 skipped_count = 0 total_count = 0 - config = current_app.config - vector_type = config.get('VECTOR_STORE') + vector_type = dify_config.VECTOR_STORE page = 1 while True: try: @@ -484,8 +483,7 @@ def convert_to_agent_apps(): @click.option('--field', default='metadata.doc_id', prompt=False, help='index field , default is metadata.doc_id.') def add_qdrant_doc_id_index(field: str): click.echo(click.style('Start add qdrant doc_id index.', fg='green')) - config = current_app.config - vector_type = config.get('VECTOR_STORE') + vector_type = dify_config.VECTOR_STORE if vector_type != "qdrant": click.echo(click.style('Sorry, only support qdrant vector store.', fg='red')) return @@ -502,13 +500,15 @@ def add_qdrant_doc_id_index(field: str): from core.rag.datasource.vdb.qdrant.qdrant_vector import QdrantConfig for binding in bindings: + if dify_config.QDRANT_URL is None: + raise ValueError('Qdrant url is required.') qdrant_config = QdrantConfig( - endpoint=config.get('QDRANT_URL'), - api_key=config.get('QDRANT_API_KEY'), + endpoint=dify_config.QDRANT_URL, + api_key=dify_config.QDRANT_API_KEY, root_path=current_app.root_path, - timeout=config.get('QDRANT_CLIENT_TIMEOUT'), - grpc_port=config.get('QDRANT_GRPC_PORT'), - prefer_grpc=config.get('QDRANT_GRPC_ENABLED') + timeout=dify_config.QDRANT_CLIENT_TIMEOUT, + grpc_port=dify_config.QDRANT_GRPC_PORT, + prefer_grpc=dify_config.QDRANT_GRPC_ENABLED ) try: client = qdrant_client.QdrantClient(**qdrant_config.to_qdrant_params()) diff --git a/api/controllers/console/auth/login.py b/api/controllers/console/auth/login.py index 3a0e5ea94d..c135ece67e 100644 --- a/api/controllers/console/auth/login.py +++ b/api/controllers/console/auth/login.py @@ -71,7 +71,7 @@ class ResetPasswordApi(Resource): # AccountService.update_password(account, new_password) # todo: Send email - # MAILCHIMP_API_KEY = current_app.config['MAILCHIMP_TRANSACTIONAL_API_KEY'] + # MAILCHIMP_API_KEY = dify_config.MAILCHIMP_TRANSACTIONAL_API_KEY # mailchimp = MailchimpTransactional(MAILCHIMP_API_KEY) # message = { @@ -92,7 +92,7 @@ class ResetPasswordApi(Resource): # 'message': message, # # required for transactional email # ' settings': { - # 'sandbox_mode': current_app.config['MAILCHIMP_SANDBOX_MODE'], + # 'sandbox_mode': dify_config.MAILCHIMP_SANDBOX_MODE, # }, # }) diff --git a/api/core/indexing_runner.py b/api/core/indexing_runner.py index 83dbacbfcc..b20c6ed187 100644 --- a/api/core/indexing_runner.py +++ b/api/core/indexing_runner.py @@ -12,6 +12,7 @@ from flask import Flask, current_app from flask_login import current_user from sqlalchemy.orm.exc import ObjectDeletedError +from configs import dify_config from core.errors.error import ProviderTokenNotInitError from core.llm_generator.llm_generator import LLMGenerator from core.model_manager import ModelInstance, ModelManager @@ -224,7 +225,7 @@ class IndexingRunner: features = FeatureService.get_features(tenant_id) if features.billing.enabled: count = len(extract_settings) - batch_upload_limit = int(current_app.config['BATCH_UPLOAD_LIMIT']) + batch_upload_limit = dify_config.BATCH_UPLOAD_LIMIT if count > batch_upload_limit: raise ValueError(f"You have reached the batch upload limit of {batch_upload_limit}.") @@ -427,7 +428,7 @@ class IndexingRunner: # The user-defined segmentation rule rules = json.loads(processing_rule.rules) segmentation = rules["segmentation"] - max_segmentation_tokens_length = int(current_app.config['INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH']) + max_segmentation_tokens_length = dify_config.INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH if segmentation["max_tokens"] < 50 or segmentation["max_tokens"] > max_segmentation_tokens_length: raise ValueError(f"Custom segment length should be between 50 and {max_segmentation_tokens_length}.") diff --git a/api/core/rag/datasource/keyword/jieba/jieba.py b/api/core/rag/datasource/keyword/jieba/jieba.py index 7f7c46e2dd..a3714c2fd3 100644 --- a/api/core/rag/datasource/keyword/jieba/jieba.py +++ b/api/core/rag/datasource/keyword/jieba/jieba.py @@ -2,9 +2,9 @@ import json from collections import defaultdict from typing import Any, Optional -from flask import current_app from pydantic import BaseModel +from configs import dify_config from core.rag.datasource.keyword.jieba.jieba_keyword_table_handler import JiebaKeywordTableHandler from core.rag.datasource.keyword.keyword_base import BaseKeyword from core.rag.models.document import Document @@ -139,7 +139,7 @@ class Jieba(BaseKeyword): if keyword_table_dict: return keyword_table_dict['__data__']['table'] else: - keyword_data_source_type = current_app.config['KEYWORD_DATA_SOURCE_TYPE'] + keyword_data_source_type = dify_config.KEYWORD_DATA_SOURCE_TYPE dataset_keyword_table = DatasetKeywordTable( dataset_id=self.dataset.id, keyword_table='', diff --git a/api/libs/passport.py b/api/libs/passport.py index 530709f18c..34bdc55997 100644 --- a/api/libs/passport.py +++ b/api/libs/passport.py @@ -1,15 +1,16 @@ import jwt -from flask import current_app from werkzeug.exceptions import Unauthorized +from configs import dify_config + class PassportService: def __init__(self): - self.sk = current_app.config.get('SECRET_KEY') - + self.sk = dify_config.SECRET_KEY + def issue(self, payload): return jwt.encode(payload, self.sk, algorithm='HS256') - + def verify(self, token): try: return jwt.decode(token, self.sk, algorithms=['HS256']) From 028261f760e330859dd0ba1360c3a0f70d623497 Mon Sep 17 00:00:00 2001 From: Chenhe Gu Date: Tue, 30 Jul 2024 14:17:45 +0800 Subject: [PATCH 02/19] improve issue templates (#6785) --- .github/DISCUSSION_TEMPLATE/general.yml | 2 +- .github/DISCUSSION_TEMPLATE/help.yml | 2 +- .github/DISCUSSION_TEMPLATE/suggestion.yml | 2 +- .github/ISSUE_TEMPLATE/bug_report.yml | 3 +-- .github/ISSUE_TEMPLATE/document_issue.yml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yml | 2 +- .github/ISSUE_TEMPLATE/translation_issue.yml | 3 +-- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/DISCUSSION_TEMPLATE/general.yml b/.github/DISCUSSION_TEMPLATE/general.yml index 5af61ea64c..487d719c85 100644 --- a/.github/DISCUSSION_TEMPLATE/general.yml +++ b/.github/DISCUSSION_TEMPLATE/general.yml @@ -9,7 +9,7 @@ body: required: true - label: I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true diff --git a/.github/DISCUSSION_TEMPLATE/help.yml b/.github/DISCUSSION_TEMPLATE/help.yml index abebaa9727..86de4057ae 100644 --- a/.github/DISCUSSION_TEMPLATE/help.yml +++ b/.github/DISCUSSION_TEMPLATE/help.yml @@ -9,7 +9,7 @@ body: required: true - label: I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true diff --git a/.github/DISCUSSION_TEMPLATE/suggestion.yml b/.github/DISCUSSION_TEMPLATE/suggestion.yml index 0893a10b2d..fa1b4e0251 100644 --- a/.github/DISCUSSION_TEMPLATE/suggestion.yml +++ b/.github/DISCUSSION_TEMPLATE/suggestion.yml @@ -9,7 +9,7 @@ body: required: true - label: I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index cf4fce3700..f767e8ba32 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -14,7 +14,7 @@ body: required: true - label: I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true @@ -22,7 +22,6 @@ body: - type: input attributes: label: Dify version - placeholder: 0.6.15 description: See about section in Dify console validations: required: true diff --git a/.github/ISSUE_TEMPLATE/document_issue.yml b/.github/ISSUE_TEMPLATE/document_issue.yml index 45ee37ca39..db8be32d95 100644 --- a/.github/ISSUE_TEMPLATE/document_issue.yml +++ b/.github/ISSUE_TEMPLATE/document_issue.yml @@ -12,7 +12,7 @@ body: required: true - label: I confirm that I am using English to submit report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 1b0eaaf4ab..f6764d35ad 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -12,7 +12,7 @@ body: required: true - label: I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true diff --git a/.github/ISSUE_TEMPLATE/translation_issue.yml b/.github/ISSUE_TEMPLATE/translation_issue.yml index 440ea92616..5d2f020f45 100644 --- a/.github/ISSUE_TEMPLATE/translation_issue.yml +++ b/.github/ISSUE_TEMPLATE/translation_issue.yml @@ -12,14 +12,13 @@ body: required: true - label: I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). required: true - - label: "请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" + - label: "[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)" required: true - label: "Please do not modify this template :) and fill in all the required fields." required: true - type: input attributes: label: Dify version - placeholder: 0.3.21 description: Hover over system tray icon or look at Settings validations: required: true From 72963d1f13416089d9fba67a9f232d461665e51f Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:45:14 +0800 Subject: [PATCH 03/19] fix: nonetype in webscraper validation (#6788) --- api/core/tools/provider/builtin/spider/spiderApp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/core/tools/provider/builtin/spider/spiderApp.py b/api/core/tools/provider/builtin/spider/spiderApp.py index 82c0df19ca..f0ed64867a 100644 --- a/api/core/tools/provider/builtin/spider/spiderApp.py +++ b/api/core/tools/provider/builtin/spider/spiderApp.py @@ -116,6 +116,7 @@ class Spider: :param params: Optional dictionary of additional parameters for the scrape request. :return: JSON response containing the scraping results. """ + params = params or {} # Add { "return_format": "markdown" } to the params if not already present if "return_format" not in params: @@ -143,6 +144,7 @@ class Spider: :param stream: Boolean indicating if the response should be streamed. Defaults to False. :return: JSON response or the raw response stream if streaming enabled. """ + params = params or {} # Add { "return_format": "markdown" } to the params if not already present if "return_format" not in params: From 0675c5f71614fc9498c18be38e28a0b194a1901c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E6=B3=95=E6=93=8D=E4=BD=9C?= Date: Tue, 30 Jul 2024 16:18:58 +0800 Subject: [PATCH 04/19] chore: add shortcut keys and hints for the shortcuts (#6779) --- web/app/components/workflow/header/undo-redo.tsx | 4 ++-- web/app/components/workflow/operator/control.tsx | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/web/app/components/workflow/header/undo-redo.tsx b/web/app/components/workflow/header/undo-redo.tsx index bd27e09173..796038ce98 100644 --- a/web/app/components/workflow/header/undo-redo.tsx +++ b/web/app/components/workflow/header/undo-redo.tsx @@ -30,7 +30,7 @@ const UndoRedo: FC = ({ handleUndo, handleRedo }) => { return (
- +
= ({ handleUndo, handleRedo }) => {
- +
{ handleLayout() } + useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.o`, (e) => { + e.preventDefault() + goLayout() + }, { exactMatch: true, useCapture: true }) + const addNote = (e: MouseEvent) => { if (getNodesReadOnly()) return @@ -101,7 +106,7 @@ const Control = () => {
- +
{
- +
{
- +
Date: Tue, 30 Jul 2024 16:59:03 +0800 Subject: [PATCH 05/19] fix: eco knowledge retrieval method (#6798) --- .../params-config/config-content.tsx | 23 ++++++++++++++++++- web/hooks/use-knowledge.ts | 7 ++++-- web/i18n/en-US/dataset.ts | 4 +++- web/i18n/zh-Hans/dataset.ts | 4 +++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/web/app/components/app/configuration/dataset-config/params-config/config-content.tsx b/web/app/components/app/configuration/dataset-config/params-config/config-content.tsx index d71d26bbed..683617bf25 100644 --- a/web/app/components/app/configuration/dataset-config/params-config/config-content.tsx +++ b/web/app/components/app/configuration/dataset-config/params-config/config-content.tsx @@ -32,6 +32,7 @@ import { RerankingModeEnum } from '@/models/datasets' import cn from '@/utils/classnames' import { useSelectedDatasetsMode } from '@/app/components/workflow/nodes/knowledge-retrieval/hooks' import Switch from '@/app/components/base/switch' +import { useGetLanguage } from '@/context/i18n' type Props = { datasetConfigs: DatasetConfigs @@ -43,6 +44,11 @@ type Props = { selectedDatasets?: DataSet[] } +const LEGACY_LINK_MAP = { + en_US: 'https://docs.dify.ai/guides/knowledge-base/integrate-knowledge-within-application', + zh_Hans: 'https://docs.dify.ai/v/zh-hans/guides/knowledge-base/integrate_knowledge_within_application', +} as Record + const ConfigContent: FC = ({ datasetConfigs, onChange, @@ -53,6 +59,7 @@ const ConfigContent: FC = ({ selectedDatasets = [], }) => { const { t } = useTranslation() + const language = useGetLanguage() const selectedDatasetsMode = useSelectedDatasetsMode(selectedDatasets) const type = datasetConfigs.retrieval_model const setType = (value: RETRIEVE_TYPE) => { @@ -167,7 +174,21 @@ const ConfigContent: FC = ({ title={(
{t('appDebug.datasetConfig.retrieveOneWay.title')} - {t('dataset.nTo1RetrievalLegacy')}
}> + + {t('dataset.nTo1RetrievalLegacy')} + + ({t('dataset.nTo1RetrievalLegacyLink')}) + +
+ )} + >
legacy
diff --git a/web/hooks/use-knowledge.ts b/web/hooks/use-knowledge.ts index 657acb3f51..400d9722de 100644 --- a/web/hooks/use-knowledge.ts +++ b/web/hooks/use-knowledge.ts @@ -8,7 +8,10 @@ export const useKnowledge = () => { return t(`dataset.indexingTechnique.${indexingTechnique}`) }, [t]) - const formatIndexingMethod = useCallback((indexingMethod: string) => { + const formatIndexingMethod = useCallback((indexingMethod: string, isEco?: boolean) => { + if (isEco) + return t('dataset.indexingMethod.invertedIndex') + return t(`dataset.indexingMethod.${indexingMethod}`) }, [t]) @@ -16,7 +19,7 @@ export const useKnowledge = () => { let result = formatIndexingTechnique(indexingTechnique) if (indexingMethod) - result += ` · ${formatIndexingMethod(indexingMethod)}` + result += ` · ${formatIndexingMethod(indexingMethod, indexingTechnique === 'economy')}` return result }, [formatIndexingTechnique, formatIndexingMethod]) diff --git a/web/i18n/en-US/dataset.ts b/web/i18n/en-US/dataset.ts index 61ed3225e6..64fda36c10 100644 --- a/web/i18n/en-US/dataset.ts +++ b/web/i18n/en-US/dataset.ts @@ -53,6 +53,7 @@ const translation = { semantic_search: 'VECTOR', full_text_search: 'FULL TEXT', hybrid_search: 'HYBRID', + invertedIndex: 'INVERTED', }, mixtureHighQualityAndEconomicTip: 'The Rerank model is required for mixture of high quality and economical knowledge bases.', inconsistentEmbeddingModelTip: 'The Rerank model is required if the Embedding models of the selected knowledge bases are inconsistent.', @@ -67,7 +68,8 @@ const translation = { semantic: 'Semantic', keyword: 'Keyword', }, - nTo1RetrievalLegacy: 'According to the optimization and upgrade of the retrieval strategy, N-to-1 retrieval will be officially deprecated in September. Until then you can still use it normally.', + nTo1RetrievalLegacy: 'N-to-1 retrieval will be officially deprecated from September. It is recommended to use the latest Multi-path retrieval to obtain better results. ', + nTo1RetrievalLegacyLink: 'Learn more', } export default translation diff --git a/web/i18n/zh-Hans/dataset.ts b/web/i18n/zh-Hans/dataset.ts index 1750c88ce3..1dd11c5c33 100644 --- a/web/i18n/zh-Hans/dataset.ts +++ b/web/i18n/zh-Hans/dataset.ts @@ -53,6 +53,7 @@ const translation = { semantic_search: '向量检索', full_text_search: '全文检索', hybrid_search: '混合检索', + invertedIndex: '倒排索引', }, mixtureHighQualityAndEconomicTip: '混合使用高质量和经济型知识库需要配置 Rerank 模型。', inconsistentEmbeddingModelTip: '当所选知识库配置的 Embedding 模型不一致时,需要配置 Rerank 模型。', @@ -67,7 +68,8 @@ const translation = { semantic: '语义', keyword: '关键词', }, - nTo1RetrievalLegacy: '为了对检索策略进行优化和升级,N 选 1 检索功能将于九月份正式被优化。在此之前,您仍然可以正常使用该功能。', + nTo1RetrievalLegacy: '9 月 1 日起我们将不再提供此能力,推荐使用最新的多路召回获得更好的检索效果。', + nTo1RetrievalLegacyLink: '了解更多', } export default translation From 53a89bbbc75edddfdfcf2b774a4b9b567c369785 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 30 Jul 2024 17:33:08 +0800 Subject: [PATCH 06/19] chore : option card (#6800) --- .../nodes/_base/components/option-card.tsx | 62 +++++++++++++++++++ .../llm/components/resolution-picker.tsx | 45 ++++---------- 2 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 web/app/components/workflow/nodes/_base/components/option-card.tsx diff --git a/web/app/components/workflow/nodes/_base/components/option-card.tsx b/web/app/components/workflow/nodes/_base/components/option-card.tsx new file mode 100644 index 0000000000..62fe8937fd --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/option-card.tsx @@ -0,0 +1,62 @@ +'use client' +import type { FC } from 'react' +import React, { useCallback } from 'react' +import type { VariantProps } from 'class-variance-authority' +import { cva } from 'class-variance-authority' +import cn from '@/utils/classnames' + +const variants = cva([], { + variants: { + align: { + left: 'justify-start', + center: 'justify-center', + right: 'justify-end', + }, + }, + defaultVariants: { + align: 'center', + }, +}, +) + +type Props = { + className?: string + title: string + onSelect: () => void + selected: boolean + disabled?: boolean + align?: 'left' | 'center' | 'right' +} & VariantProps + +const OptionCard: FC = ({ + className, + title, + onSelect, + selected, + disabled, + align = 'center', +}) => { + const handleSelect = useCallback(() => { + if (selected || disabled) + return + onSelect() + }, [onSelect, selected, disabled]) + + return ( +
+ {title} +
+ ) +} + +export default React.memo(OptionCard) diff --git a/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx b/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx index 6ea48b1f72..76763de520 100644 --- a/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx +++ b/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx @@ -2,35 +2,11 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' -import cn from '@/utils/classnames' +import OptionCard from '@/app/components/workflow/nodes/_base/components/option-card' import { Resolution } from '@/types/app' const i18nPrefix = 'workflow.nodes.llm' -type ItemProps = { - title: string - value: Resolution - onSelect: (value: Resolution) => void - isSelected: boolean -} - -const Item: FC = ({ title, value, onSelect, isSelected }) => { - const handleSelect = useCallback(() => { - if (isSelected) - return - onSelect(value) - }, [value, onSelect, isSelected]) - - return ( -
- {title} -
- ) -} - type Props = { value: Resolution onChange: (value: Resolution) => void @@ -42,21 +18,24 @@ const ResolutionPicker: FC = ({ }) => { const { t } = useTranslation() + const handleOnChange = useCallback((value: Resolution) => { + return () => { + onChange(value) + } + }, [onChange]) return (
{t(`${i18nPrefix}.resolution.name`)}
- -
From 98d9837fbc78d21d96e6a2e1d608c818040ebc51 Mon Sep 17 00:00:00 2001 From: eric-0x72 <1466870240@qq.com> Date: Tue, 30 Jul 2024 21:32:45 +0800 Subject: [PATCH 07/19] fix wrong charset when decoding Chinese content (#6774) Co-authored-by: zhangwb --- api/core/tools/utils/web_reader_tool.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api/core/tools/utils/web_reader_tool.py b/api/core/tools/utils/web_reader_tool.py index f6f04271d6..a461328ae6 100644 --- a/api/core/tools/utils/web_reader_tool.py +++ b/api/core/tools/utils/web_reader_tool.py @@ -10,6 +10,7 @@ import unicodedata from contextlib import contextmanager from urllib.parse import unquote +import chardet import cloudscraper from bs4 import BeautifulSoup, CData, Comment, NavigableString from regex import regex @@ -75,7 +76,18 @@ def get_url(url: str, user_agent: str = None) -> str: if response.status_code != 200: return "URL returned status code {}.".format(response.status_code) - a = extract_using_readabilipy(response.text) + # Detect encoding using chardet + detected_encoding = chardet.detect(response.content) + encoding = detected_encoding['encoding'] + if encoding: + try: + content = response.content.decode(encoding) + except (UnicodeDecodeError, TypeError): + content = response.text + else: + content = response.text + + a = extract_using_readabilipy(content) if not a['plain_text'] or not a['plain_text'].strip(): return '' From 9ce5cea911589f5f80f5b302b5fcbf0cef618bfb Mon Sep 17 00:00:00 2001 From: longzhihun <38651850@qq.com> Date: Tue, 30 Jul 2024 21:57:18 +0800 Subject: [PATCH 08/19] feat: bedrock invoke enhancement (#6808) --- .../bedrock/llm/_position.yaml | 1 + .../llm/cohere.command-r-plus-v1.0.yaml | 3 +- .../bedrock/llm/cohere.command-r-v1.0.yaml | 4 +- .../model_providers/bedrock/llm/llm.py | 184 +----------------- .../llm/meta.llama3-1-405b-instruct-v1.0.yaml | 25 +++ 5 files changed, 37 insertions(+), 180 deletions(-) create mode 100644 api/core/model_runtime/model_providers/bedrock/llm/meta.llama3-1-405b-instruct-v1.0.yaml diff --git a/api/core/model_runtime/model_providers/bedrock/llm/_position.yaml b/api/core/model_runtime/model_providers/bedrock/llm/_position.yaml index c523596b57..86c8061dee 100644 --- a/api/core/model_runtime/model_providers/bedrock/llm/_position.yaml +++ b/api/core/model_runtime/model_providers/bedrock/llm/_position.yaml @@ -12,6 +12,7 @@ - cohere.command-r-v1.0 - meta.llama3-1-8b-instruct-v1:0 - meta.llama3-1-70b-instruct-v1:0 +- meta.llama3-1-405b-instruct-v1:0 - meta.llama3-8b-instruct-v1:0 - meta.llama3-70b-instruct-v1:0 - meta.llama2-13b-chat-v1 diff --git a/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-plus-v1.0.yaml b/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-plus-v1.0.yaml index 4ecf3dd2fd..3c0bb4e8d5 100644 --- a/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-plus-v1.0.yaml +++ b/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-plus-v1.0.yaml @@ -3,8 +3,7 @@ label: en_US: Command R+ model_type: llm features: - #- multi-tool-call - - agent-thought + - tool-call #- stream-tool-call model_properties: mode: chat diff --git a/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-v1.0.yaml b/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-v1.0.yaml index b7a12b480a..a34f48319f 100644 --- a/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-v1.0.yaml +++ b/api/core/model_runtime/model_providers/bedrock/llm/cohere.command-r-v1.0.yaml @@ -3,9 +3,7 @@ label: en_US: Command R model_type: llm features: - #- multi-tool-call - - agent-thought - #- stream-tool-call + - tool-call model_properties: mode: chat context_size: 128000 diff --git a/api/core/model_runtime/model_providers/bedrock/llm/llm.py b/api/core/model_runtime/model_providers/bedrock/llm/llm.py index e9906c8294..ff34a116c7 100644 --- a/api/core/model_runtime/model_providers/bedrock/llm/llm.py +++ b/api/core/model_runtime/model_providers/bedrock/llm/llm.py @@ -17,7 +17,6 @@ from botocore.exceptions import ( ServiceNotInRegionError, UnknownServiceError, ) -from cohere import ChatMessage # local import from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta @@ -42,7 +41,6 @@ from core.model_runtime.errors.invoke import ( ) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel -from core.model_runtime.model_providers.cohere.llm.llm import CohereLargeLanguageModel logger = logging.getLogger(__name__) @@ -59,6 +57,7 @@ class BedrockLargeLanguageModel(LargeLanguageModel): {'prefix': 'mistral.mixtral-8x7b-instruct', 'support_system_prompts': False, 'support_tool_use': False}, {'prefix': 'mistral.mistral-large', 'support_system_prompts': True, 'support_tool_use': True}, {'prefix': 'mistral.mistral-small', 'support_system_prompts': True, 'support_tool_use': True}, + {'prefix': 'cohere.command-r', 'support_system_prompts': True, 'support_tool_use': True}, {'prefix': 'amazon.titan', 'support_system_prompts': False, 'support_tool_use': False} ] @@ -94,86 +93,8 @@ class BedrockLargeLanguageModel(LargeLanguageModel): model_info['model'] = model # invoke models via boto3 converse API return self._generate_with_converse(model_info, credentials, prompt_messages, model_parameters, stop, stream, user, tools) - # invoke Cohere models via boto3 client - if "cohere.command-r" in model: - return self._generate_cohere_chat(model, credentials, prompt_messages, model_parameters, stop, stream, user, tools) # invoke other models via boto3 client return self._generate(model, credentials, prompt_messages, model_parameters, stop, stream, user) - - def _generate_cohere_chat( - self, model: str, credentials: dict, prompt_messages: list[PromptMessage], model_parameters: dict, - stop: Optional[list[str]] = None, stream: bool = True, user: Optional[str] = None, - tools: Optional[list[PromptMessageTool]] = None,) -> Union[LLMResult, Generator]: - cohere_llm = CohereLargeLanguageModel() - client_config = Config( - region_name=credentials["aws_region"] - ) - - runtime_client = boto3.client( - service_name='bedrock-runtime', - config=client_config, - aws_access_key_id=credentials["aws_access_key_id"], - aws_secret_access_key=credentials["aws_secret_access_key"] - ) - - extra_model_kwargs = {} - if stop: - extra_model_kwargs['stop_sequences'] = stop - - if tools: - tools = cohere_llm._convert_tools(tools) - model_parameters['tools'] = tools - - message, chat_histories, tool_results \ - = cohere_llm._convert_prompt_messages_to_message_and_chat_histories(prompt_messages) - - if tool_results: - model_parameters['tool_results'] = tool_results - - payload = { - **model_parameters, - "message": message, - "chat_history": chat_histories, - } - - # need workaround for ai21 models which doesn't support streaming - if stream: - invoke = runtime_client.invoke_model_with_response_stream - else: - invoke = runtime_client.invoke_model - - def serialize(obj): - if isinstance(obj, ChatMessage): - return obj.__dict__ - raise TypeError(f"Type {type(obj)} not serializable") - - try: - body_jsonstr=json.dumps(payload, default=serialize) - response = invoke( - modelId=model, - contentType="application/json", - accept="*/*", - body=body_jsonstr - ) - except ClientError as ex: - error_code = ex.response['Error']['Code'] - full_error_msg = f"{error_code}: {ex.response['Error']['Message']}" - raise self._map_client_to_invoke_error(error_code, full_error_msg) - - except (EndpointConnectionError, NoRegionError, ServiceNotInRegionError) as ex: - raise InvokeConnectionError(str(ex)) - - except UnknownServiceError as ex: - raise InvokeServerUnavailableError(str(ex)) - - except Exception as ex: - raise InvokeError(str(ex)) - - if stream: - return self._handle_generate_stream_response(model, credentials, response, prompt_messages) - - return self._handle_generate_response(model, credentials, response, prompt_messages) - def _generate_with_converse(self, model_info: dict, credentials: dict, prompt_messages: list[PromptMessage], model_parameters: dict, stop: Optional[list[str]] = None, stream: bool = True, user: Optional[str] = None, tools: Optional[list[PromptMessageTool]] = None,) -> Union[LLMResult, Generator]: @@ -581,38 +502,9 @@ class BedrockLargeLanguageModel(LargeLanguageModel): :param message: PromptMessage to convert. :return: String representation of the message. """ - - if model_prefix == "anthropic": - human_prompt_prefix = "\n\nHuman:" - human_prompt_postfix = "" - ai_prompt = "\n\nAssistant:" - - elif model_prefix == "meta": - # LLAMA3 - if model_name.startswith("llama3"): - human_prompt_prefix = "<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n" - human_prompt_postfix = "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n" - ai_prompt = "\n\nAssistant:" - else: - # LLAMA2 - human_prompt_prefix = "\n[INST]" - human_prompt_postfix = "[\\INST]\n" - ai_prompt = "" - - elif model_prefix == "mistral": - human_prompt_prefix = "[INST]" - human_prompt_postfix = "[\\INST]\n" - ai_prompt = "\n\nAssistant:" - - elif model_prefix == "amazon": - human_prompt_prefix = "\n\nUser:" - human_prompt_postfix = "" - ai_prompt = "\n\nBot:" - - else: - human_prompt_prefix = "" - human_prompt_postfix = "" - ai_prompt = "" + human_prompt_prefix = "" + human_prompt_postfix = "" + ai_prompt = "" content = message.content @@ -663,13 +555,7 @@ class BedrockLargeLanguageModel(LargeLanguageModel): model_prefix = model.split('.')[0] model_name = model.split('.')[1] - if model_prefix == "amazon": - payload["textGenerationConfig"] = { **model_parameters } - payload["textGenerationConfig"]["stopSequences"] = ["User:"] - - payload["inputText"] = self._convert_messages_to_prompt(prompt_messages, model_prefix) - - elif model_prefix == "ai21": + if model_prefix == "ai21": payload["temperature"] = model_parameters.get("temperature") payload["topP"] = model_parameters.get("topP") payload["maxTokens"] = model_parameters.get("maxTokens") @@ -681,28 +567,12 @@ class BedrockLargeLanguageModel(LargeLanguageModel): payload["frequencyPenalty"] = {model_parameters.get("frequencyPenalty")} if model_parameters.get("countPenalty"): payload["countPenalty"] = {model_parameters.get("countPenalty")} - - elif model_prefix == "mistral": - payload["temperature"] = model_parameters.get("temperature") - payload["top_p"] = model_parameters.get("top_p") - payload["max_tokens"] = model_parameters.get("max_tokens") - payload["prompt"] = self._convert_messages_to_prompt(prompt_messages, model_prefix) - payload["stop"] = stop[:10] if stop else [] - - elif model_prefix == "anthropic": - payload = { **model_parameters } - payload["prompt"] = self._convert_messages_to_prompt(prompt_messages, model_prefix) - payload["stop_sequences"] = ["\n\nHuman:"] + (stop if stop else []) - + elif model_prefix == "cohere": payload = { **model_parameters } payload["prompt"] = prompt_messages[0].content payload["stream"] = stream - elif model_prefix == "meta": - payload = { **model_parameters } - payload["prompt"] = self._convert_messages_to_prompt(prompt_messages, model_prefix, model_name) - else: raise ValueError(f"Got unknown model prefix {model_prefix}") @@ -793,36 +663,16 @@ class BedrockLargeLanguageModel(LargeLanguageModel): # get output text and calculate num tokens based on model / provider model_prefix = model.split('.')[0] - if model_prefix == "amazon": - output = response_body.get("results")[0].get("outputText").strip('\n') - prompt_tokens = response_body.get("inputTextTokenCount") - completion_tokens = response_body.get("results")[0].get("tokenCount") - - elif model_prefix == "ai21": + if model_prefix == "ai21": output = response_body.get('completions')[0].get('data').get('text') prompt_tokens = len(response_body.get("prompt").get("tokens")) completion_tokens = len(response_body.get('completions')[0].get('data').get('tokens')) - - elif model_prefix == "anthropic": - output = response_body.get("completion") - prompt_tokens = self.get_num_tokens(model, credentials, prompt_messages) - completion_tokens = self.get_num_tokens(model, credentials, output if output else '') elif model_prefix == "cohere": output = response_body.get("generations")[0].get("text") prompt_tokens = self.get_num_tokens(model, credentials, prompt_messages) completion_tokens = self.get_num_tokens(model, credentials, output if output else '') - - elif model_prefix == "meta": - output = response_body.get("generation").strip('\n') - prompt_tokens = response_body.get("prompt_token_count") - completion_tokens = response_body.get("generation_token_count") - - elif model_prefix == "mistral": - output = response_body.get("outputs")[0].get("text") - prompt_tokens = response.get('ResponseMetadata').get('HTTPHeaders').get('x-amzn-bedrock-input-token-count') - completion_tokens = response.get('ResponseMetadata').get('HTTPHeaders').get('x-amzn-bedrock-output-token-count') - + else: raise ValueError(f"Got unknown model prefix {model_prefix} when handling block response") @@ -893,26 +743,10 @@ class BedrockLargeLanguageModel(LargeLanguageModel): payload = json.loads(chunk.get('bytes').decode()) model_prefix = model.split('.')[0] - if model_prefix == "amazon": - content_delta = payload.get("outputText").strip('\n') - finish_reason = payload.get("completion_reason") - - elif model_prefix == "anthropic": - content_delta = payload.get("completion") - finish_reason = payload.get("stop_reason") - - elif model_prefix == "cohere": + if model_prefix == "cohere": content_delta = payload.get("text") finish_reason = payload.get("finish_reason") - elif model_prefix == "mistral": - content_delta = payload.get('outputs')[0].get("text") - finish_reason = payload.get('outputs')[0].get("stop_reason") - - elif model_prefix == "meta": - content_delta = payload.get("generation").strip('\n') - finish_reason = payload.get("stop_reason") - else: raise ValueError(f"Got unknown model prefix {model_prefix} when handling stream response") diff --git a/api/core/model_runtime/model_providers/bedrock/llm/meta.llama3-1-405b-instruct-v1.0.yaml b/api/core/model_runtime/model_providers/bedrock/llm/meta.llama3-1-405b-instruct-v1.0.yaml new file mode 100644 index 0000000000..401de65f89 --- /dev/null +++ b/api/core/model_runtime/model_providers/bedrock/llm/meta.llama3-1-405b-instruct-v1.0.yaml @@ -0,0 +1,25 @@ +model: meta.llama3-1-405b-instruct-v1:0 +label: + en_US: Llama 3.1 405B Instruct +model_type: llm +model_properties: + mode: completion + context_size: 128000 +parameter_rules: + - name: temperature + use_template: temperature + default: 0.5 + - name: top_p + use_template: top_p + default: 0.9 + - name: max_gen_len + use_template: max_tokens + required: true + default: 512 + min: 1 + max: 2048 +pricing: + input: '0.00532' + output: '0.016' + unit: '0.001' + currency: USD From 3c371a6cb0fd74785055b8a6cb56b9de7dfc1c7a Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Tue, 30 Jul 2024 23:51:48 +0800 Subject: [PATCH 09/19] fix: workflow api (#6810) --- api/controllers/service_api/app/workflow.py | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/api/controllers/service_api/app/workflow.py b/api/controllers/service_api/app/workflow.py index 10484c9027..9446f9d588 100644 --- a/api/controllers/service_api/app/workflow.py +++ b/api/controllers/service_api/app/workflow.py @@ -29,22 +29,21 @@ from services.app_generate_service import AppGenerateService logger = logging.getLogger(__name__) +workflow_run_fields = { + 'id': fields.String, + 'workflow_id': fields.String, + 'status': fields.String, + 'inputs': fields.Raw, + 'outputs': fields.Raw, + 'error': fields.String, + 'total_steps': fields.Integer, + 'total_tokens': fields.Integer, + 'created_at': fields.DateTime, + 'finished_at': fields.DateTime, + 'elapsed_time': fields.Float, +} -class WorkflowRunApi(Resource): - workflow_run_fields = { - 'id': fields.String, - 'workflow_id': fields.String, - 'status': fields.String, - 'inputs': fields.Raw, - 'outputs': fields.Raw, - 'error': fields.String, - 'total_steps': fields.Integer, - 'total_tokens': fields.Integer, - 'created_at': fields.DateTime, - 'finished_at': fields.DateTime, - 'elapsed_time': fields.Float, - } - +class WorkflowRunDetailApi(Resource): @validate_app_token @marshal_with(workflow_run_fields) def get(self, app_model: App, workflow_id: str): @@ -57,7 +56,7 @@ class WorkflowRunApi(Resource): workflow_run = db.session.query(WorkflowRun).filter(WorkflowRun.id == workflow_id).first() return workflow_run - +class WorkflowRunApi(Resource): @validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.JSON, required=True)) def post(self, app_model: App, end_user: EndUser): """ @@ -117,5 +116,6 @@ class WorkflowTaskStopApi(Resource): } -api.add_resource(WorkflowRunApi, '/workflows/run/', '/workflows/run') +api.add_resource(WorkflowRunApi, '/workflows/run') +api.add_resource(WorkflowRunDetailApi, '/workflows/run/') api.add_resource(WorkflowTaskStopApi, '/workflows/tasks//stop') From 545d3c5a93216067b5df4185c2a997904e1817b0 Mon Sep 17 00:00:00 2001 From: Ever <439674061@qq.com> Date: Wed, 31 Jul 2024 00:21:16 +0800 Subject: [PATCH 10/19] chore: Add processId field for metrics of threads/db-pool-stat/health (#6797) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 老潮 Co-authored-by: takatost Co-authored-by: takatost --- api/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/app.py b/api/app.py index 2c484ace85..50441cb81d 100644 --- a/api/app.py +++ b/api/app.py @@ -261,6 +261,7 @@ def after_request(response): @app.route('/health') def health(): return Response(json.dumps({ + 'pid': os.getpid(), 'status': 'ok', 'version': app.config['CURRENT_VERSION'] }), status=200, content_type="application/json") @@ -284,6 +285,7 @@ def threads(): }) return { + 'pid': os.getpid(), 'thread_num': num_threads, 'threads': thread_list } @@ -293,6 +295,7 @@ def threads(): def pool_stat(): engine = db.engine return { + 'pid': os.getpid(), 'pool_size': engine.pool.size(), 'checked_in_connections': engine.pool.checkedin(), 'checked_out_connections': engine.pool.checkedout(), From 936ac8826d4e1b486ca60a8b669ab4637b3764d2 Mon Sep 17 00:00:00 2001 From: k-brahma <43232136+k-brahma@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:21:56 +0900 Subject: [PATCH 11/19] Add docker-compose certbot configurations with backward compatibility (#6702) Co-authored-by: Your Name --- .gitignore | 1 + docker/.env.example | 18 ++++- docker/README.md | 91 ++++++++++++++--------- docker/certbot/README.md | 76 +++++++++++++++++++ docker/certbot/docker-entrypoint.sh | 30 ++++++++ docker/certbot/update-cert.template.txt | 19 +++++ docker/docker-compose.yaml | 35 +++++++-- docker/nginx/conf.d/default.conf.template | 3 + docker/nginx/docker-entrypoint.sh | 20 +++++ docker/nginx/https.conf.template | 4 +- 10 files changed, 253 insertions(+), 44 deletions(-) create mode 100644 docker/certbot/README.md create mode 100755 docker/certbot/docker-entrypoint.sh create mode 100755 docker/certbot/update-cert.template.txt diff --git a/.gitignore b/.gitignore index 97b7333dde..c52b9d8bbf 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ docker-legacy/volumes/milvus/* docker-legacy/volumes/chroma/* docker/volumes/app/storage/* +docker/volumes/certbot/* docker/volumes/db/data/* docker/volumes/redis/data/* docker/volumes/weaviate/* diff --git a/docker/.env.example b/docker/.env.example index 2f8ec358f4..fa0b0d6950 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -601,6 +601,22 @@ NGINX_KEEPALIVE_TIMEOUT=65 NGINX_PROXY_READ_TIMEOUT=3600s NGINX_PROXY_SEND_TIMEOUT=3600s +NGINX_ENABLE_CERTBOT_CHALLENGE=false + +# ------------------------------ +# Certbot Configuration +# ------------------------------ + +# Email address (required to get certificates from Let's Encrypt) +CERTBOT_EMAIL=your_email@example.com + +# Domain name +CERTBOT_DOMAIN=your_domain.com + +# certbot command options +# i.e: --force-renewal --dry-run --test-cert --debug +CERTBOT_OPTIONS= + # ------------------------------ # Environment Variables for SSRF Proxy # ------------------------------ @@ -611,7 +627,7 @@ SSRF_SANDBOX_HOST=sandbox # ------------------------------ # docker env var for specifying vector db type at startup -# (based on the vector db type, the corresponding docker +# (based on the vector db type, the corresponding docker # compose profile will be used) # ------------------------------ COMPOSE_PROFILES=${VECTOR_STORE:-weaviate} diff --git a/docker/README.md b/docker/README.md index 6bff8bc314..86c367a63f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,86 +3,105 @@ Welcome to the new `docker` directory for deploying Dify using Docker Compose. This README outlines the updates, deployment instructions, and migration details for existing users. ### What's Updated -- **Persistent Environment Variables**: Environment variables are now managed through a `.env` file, ensuring that your configurations persist across deployments. - > What is `.env`?

- > The `.env` file is a crucial component in Docker and Docker Compose environments, serving as a centralized configuration file where you can define environment variables that are accessible to the containers at runtime. This file simplifies the management of environment settings across different stages of development, testing, and production, providing consistency and ease of configuration to deployments. +- **Certbot Container**: `docker-compose.yaml` now contains `certbot` for managing SSL certificates. This container automatically renews certificates and ensures secure HTTPS connections. + For more information, refer `docker/certbot/README.md`. -- **Unified Vector Database Services**: All vector database services are now managed from a single Docker Compose file `docker-compose.yaml`. You can switch between different vector databases by setting the `VECTOR_STORE` environment variable in your `.env` file. -- **Mandatory .env File**: A `.env` file is now required to run `docker compose up`. This file is crucial for configuring your deployment and for any custom settings to persist through upgrades. -- **Legacy Support**: Previous deployment files are now located in the `docker-legacy` directory and will no longer be maintained. +- **Persistent Environment Variables + **: Environment variables are now managed through a `.env` file, ensuring that your configurations persist across deployments. + + > What is `.env`?

+ > The `.env` file is a crucial component in Docker and Docker Compose environments, serving as a centralized configuration file where you can define environment variables that are accessible to the containers at runtime. This file simplifies the management of environment settings across different stages of development, testing, and production, providing consistency and ease of configuration to deployments. + +- **Unified Vector Database Services + **: All vector database services are now managed from a single Docker Compose file `docker-compose.yaml`. You can switch between different vector databases by setting the `VECTOR_STORE` environment variable in your `.env` file. +- **Mandatory .env File + **: A `.env` file is now required to run `docker compose up`. This file is crucial for configuring your deployment and for any custom settings to persist through upgrades. +- **Legacy Support + **: Previous deployment files are now located in the `docker-legacy` directory and will no longer be maintained. ### How to Deploy Dify with `docker-compose.yaml` + 1. **Prerequisites**: Ensure Docker and Docker Compose are installed on your system. 2. **Environment Setup**: - - Navigate to the `docker` directory. - - Copy the `.env.example` file to a new file named `.env` by running `cp .env.example .env`. - - Customize the `.env` file as needed. Refer to the `.env.example` file for detailed configuration options. + - Navigate to the `docker` directory. + - Copy the `.env.example` file to a new file named `.env` by running `cp .env.example .env`. + - Customize the `.env` file as needed. Refer to the `.env.example` file for detailed configuration options. 3. **Running the Services**: - - Execute `docker compose up` from the `docker` directory to start the services. - - To specify a vector database, set the `VECTOR_store` variable in your `.env` file to your desired vector database service, such as `milvus`, `weaviate`, or `opensearch`. + - Execute `docker compose up` from the `docker` directory to start the services. + - To specify a vector database, set the `VECTOR_store` variable in your `.env` file to your desired vector database service, such as `milvus`, `weaviate`, or `opensearch`. +4. **SSL Certificate Setup**: + - Rrefer `docker/certbot/README.md` to set up SSL certificates using Certbot. ### How to Deploy Middleware for Developing Dify + 1. **Middleware Setup**: - - Use the `docker-compose.middleware.yaml` for setting up essential middleware services like databases and caches. - - Navigate to the `docker` directory. - - Ensure the `middleware.env` file is created by running `cp middleware.env.example middleware.env` (refer to the `middleware.env.example` file). + - Use the `docker-compose.middleware.yaml` for setting up essential middleware services like databases and caches. + - Navigate to the `docker` directory. + - Ensure the `middleware.env` file is created by running `cp middleware.env.example middleware.env` (refer to the `middleware.env.example` file). 2. **Running Middleware Services**: - - Execute `docker-compose -f docker-compose.middleware.yaml up -d` to start the middleware services. + - Execute `docker-compose -f docker-compose.middleware.yaml up -d` to start the middleware services. ### Migration for Existing Users + For users migrating from the `docker-legacy` setup: + 1. **Review Changes**: Familiarize yourself with the new `.env` configuration and Docker Compose setup. 2. **Transfer Customizations**: - - If you have customized configurations such as `docker-compose.yaml`, `ssrf_proxy/squid.conf`, or `nginx/conf.d/default.conf`, you will need to reflect these changes in the `.env` file you create. + - If you have customized configurations such as `docker-compose.yaml`, `ssrf_proxy/squid.conf`, or `nginx/conf.d/default.conf`, you will need to reflect these changes in the `.env` file you create. 3. **Data Migration**: - - Ensure that data from services like databases and caches is backed up and migrated appropriately to the new structure if necessary. + - Ensure that data from services like databases and caches is backed up and migrated appropriately to the new structure if necessary. -### Overview of `.env` +### Overview of `.env` #### Key Modules and Customization -- **Vector Database Services**: Depending on the type of vector database used (`VECTOR_STORE`), users can set specific endpoints, ports, and authentication details. -- **Storage Services**: Depending on the storage type (`STORAGE_TYPE`), users can configure specific settings for S3, Azure Blob, Google Storage, etc. +- **Vector Database Services + **: Depending on the type of vector database used (`VECTOR_STORE`), users can set specific endpoints, ports, and authentication details. +- **Storage Services + **: Depending on the storage type (`STORAGE_TYPE`), users can configure specific settings for S3, Azure Blob, Google Storage, etc. - **API and Web Services**: Users can define URLs and other settings that affect how the API and web frontends operate. #### Other notable variables + The `.env.example` file provided in the Docker setup is extensive and covers a wide range of configuration options. It is structured into several sections, each pertaining to different aspects of the application and its services. Here are some of the key sections and variables: 1. **Common Variables**: - - `CONSOLE_API_URL`, `SERVICE_API_URL`: URLs for different API services. - - `APP_WEB_URL`: Frontend application URL. - - `FILES_URL`: Base URL for file downloads and previews. + - `CONSOLE_API_URL`, `SERVICE_API_URL`: URLs for different API services. + - `APP_WEB_URL`: Frontend application URL. + - `FILES_URL`: Base URL for file downloads and previews. 2. **Server Configuration**: - - `LOG_LEVEL`, `DEBUG`, `FLASK_DEBUG`: Logging and debug settings. - - `SECRET_KEY`: A key for encrypting session cookies and other sensitive data. + - `LOG_LEVEL`, `DEBUG`, `FLASK_DEBUG`: Logging and debug settings. + - `SECRET_KEY`: A key for encrypting session cookies and other sensitive data. 3. **Database Configuration**: - - `DB_USERNAME`, `DB_PASSWORD`, `DB_HOST`, `DB_PORT`, `DB_DATABASE`: PostgreSQL database credentials and connection details. + - `DB_USERNAME`, `DB_PASSWORD`, `DB_HOST`, `DB_PORT`, `DB_DATABASE`: PostgreSQL database credentials and connection details. 4. **Redis Configuration**: - - `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD`: Redis server connection settings. + - `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD`: Redis server connection settings. 5. **Celery Configuration**: - - `CELERY_BROKER_URL`: Configuration for Celery message broker. + - `CELERY_BROKER_URL`: Configuration for Celery message broker. 6. **Storage Configuration**: - - `STORAGE_TYPE`, `S3_BUCKET_NAME`, `AZURE_BLOB_ACCOUNT_NAME`: Settings for file storage options like local, S3, Azure Blob, etc. + - `STORAGE_TYPE`, `S3_BUCKET_NAME`, `AZURE_BLOB_ACCOUNT_NAME`: Settings for file storage options like local, S3, Azure Blob, etc. 7. **Vector Database Configuration**: - - `VECTOR_STORE`: Type of vector database (e.g., `weaviate`, `milvus`). - - Specific settings for each vector store like `WEAVIATE_ENDPOINT`, `MILVUS_HOST`. + - `VECTOR_STORE`: Type of vector database (e.g., `weaviate`, `milvus`). + - Specific settings for each vector store like `WEAVIATE_ENDPOINT`, `MILVUS_HOST`. 8. **CORS Configuration**: - - `WEB_API_CORS_ALLOW_ORIGINS`, `CONSOLE_CORS_ALLOW_ORIGINS`: Settings for cross-origin resource sharing. + - `WEB_API_CORS_ALLOW_ORIGINS`, `CONSOLE_CORS_ALLOW_ORIGINS`: Settings for cross-origin resource sharing. 9. **Other Service-Specific Environment Variables**: - - Each service like `nginx`, `redis`, `db`, and vector databases have specific environment variables that are directly referenced in the `docker-compose.yaml`. - + - Each service like `nginx`, `redis`, `db`, and vector databases have specific environment variables that are directly referenced in the `docker-compose.yaml`. ### Additional Information -- **Continuous Improvement Phase**: We are actively seeking feedback from the community to refine and enhance the deployment process. As more users adopt this new method, we will continue to make improvements based on your experiences and suggestions. -- **Support**: For detailed configuration options and environment variable settings, refer to the `.env.example` file and the Docker Compose configuration files in the `docker` directory. + +- **Continuous Improvement Phase + **: We are actively seeking feedback from the community to refine and enhance the deployment process. As more users adopt this new method, we will continue to make improvements based on your experiences and suggestions. +- **Support + **: For detailed configuration options and environment variable settings, refer to the `.env.example` file and the Docker Compose configuration files in the `docker` directory. This README aims to guide you through the deployment process using the new Docker Compose setup. For any issues or further assistance, please refer to the official documentation or contact support. \ No newline at end of file diff --git a/docker/certbot/README.md b/docker/certbot/README.md new file mode 100644 index 0000000000..3fab2f4bb7 --- /dev/null +++ b/docker/certbot/README.md @@ -0,0 +1,76 @@ +# Launching new servers with SSL certificates + +## Short description + +Docker-compose certbot configurations with Backward compatibility (without certbot container). +Use `docker-compose --profile certbot up` to use this features. + +## The simplest way for launching new servers with SSL certificates + +1. Get letsencrypt certs + set `.env` values + ```properties + NGINX_SSL_CERT_FILENAME=fullchain.pem + NGINX_SSL_CERT_KEY_FILENAME=privkey.pem + NGINX_ENABLE_CERTBOT_CHALLENGE=true + CERTBOT_DOMAIN=your_domain.com + CERTBOT_EMAIL=example@your_domain.com + ``` + excecute command: + ```shell + sudo docker network prune + sudo docker-compose --profile certbot up --force-recreate -d + ``` + then after the containers launched: + ```shell + sudo docker-compose exec -it certbot /bin/sh /update-cert.sh + ``` +2. Edit `.env` file and `sudo docker-compose --profile certbot up` again. + set `.env` value additionally + ```properties + NGINX_HTTPS_ENABLED=true + ``` + excecute command: + ```shell + sudo docker-compose --profile certbot up -d --no-deps --force-recreate nginx + ``` + Then you can access your serve with HTTPS. + [https://your_domain.com](https://your_domain.com) + +## SSL certificates renewal + +For SSL certificates renewal, execute commands below: + +```shell +sudo docker-compose exec -it certbot /bin/sh /update-cert.sh +sudo docker-compose exec nginx nginx -s reload +``` + +## Options for certbot + +`CERTBOT_OPTIONS` key might be helpful for testing. i.e., + +```properties +CERTBOT_OPTIONS=--dry-run +``` + +To apply changes to `CERTBOT_OPTIONS`, regenerate the certbot container before updating the certificates. + +```shell +sudo docker-compose --profile certbot up -d --no-deps --force-recreate certbot +sudo docker-compose exec -it certbot /bin/sh /update-cert.sh +``` + +Then, reload the nginx container if necessary. + +```shell +sudo docker-compose exec nginx nginx -s reload +``` + +## For legacy servers + +To use cert files dir `nginx/ssl` as before, simply launch containers WITHOUT `--profile certbot` option. + +```shell +sudo docker-compose up -d +``` \ No newline at end of file diff --git a/docker/certbot/docker-entrypoint.sh b/docker/certbot/docker-entrypoint.sh new file mode 100755 index 0000000000..a70ecd8254 --- /dev/null +++ b/docker/certbot/docker-entrypoint.sh @@ -0,0 +1,30 @@ +#!/bin/sh +set -e + +printf '%s\n' "Docker entrypoint script is running" + +printf '%s\n' "\nChecking specific environment variables:" +printf '%s\n' "CERTBOT_EMAIL: ${CERTBOT_EMAIL:-Not set}" +printf '%s\n' "CERTBOT_DOMAIN: ${CERTBOT_DOMAIN:-Not set}" +printf '%s\n' "CERTBOT_OPTIONS: ${CERTBOT_OPTIONS:-Not set}" + +printf '%s\n' "\nChecking mounted directories:" +for dir in "/etc/letsencrypt" "/var/www/html" "/var/log/letsencrypt"; do + if [ -d "$dir" ]; then + printf '%s\n' "$dir exists. Contents:" + ls -la "$dir" + else + printf '%s\n' "$dir does not exist." + fi +done + +printf '%s\n' "\nGenerating update-cert.sh from template" +sed -e "s|\${CERTBOT_EMAIL}|$CERTBOT_EMAIL|g" \ + -e "s|\${CERTBOT_DOMAIN}|$CERTBOT_DOMAIN|g" \ + -e "s|\${CERTBOT_OPTIONS}|$CERTBOT_OPTIONS|g" \ + /update-cert.template.txt > /update-cert.sh + +chmod +x /update-cert.sh + +printf '%s\n' "\nExecuting command:" "$@" +exec "$@" diff --git a/docker/certbot/update-cert.template.txt b/docker/certbot/update-cert.template.txt new file mode 100755 index 0000000000..16786a192e --- /dev/null +++ b/docker/certbot/update-cert.template.txt @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +DOMAIN="${CERTBOT_DOMAIN}" +EMAIL="${CERTBOT_EMAIL}" +OPTIONS="${CERTBOT_OPTIONS}" +CERT_NAME="${DOMAIN}" # 証明書名をドメイン名と同じにする + +# Check if the certificate already exists +if [ -f "/etc/letsencrypt/renewal/${CERT_NAME}.conf" ]; then + echo "Certificate exists. Attempting to renew..." + certbot renew --noninteractive --cert-name ${CERT_NAME} --webroot --webroot-path=/var/www/html --email ${EMAIL} --agree-tos --no-eff-email ${OPTIONS} +else + echo "Certificate does not exist. Obtaining a new certificate..." + certbot certonly --noninteractive --webroot --webroot-path=/var/www/html --email ${EMAIL} --agree-tos --no-eff-email -d ${DOMAIN} ${OPTIONS} +fi +echo "Certificate operation successful" +# Note: Nginx reload should be handled outside this container +echo "Please ensure to reload Nginx to apply any certificate changes." diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index a9b7b8acb0..6a3d61b309 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -295,6 +295,26 @@ services: - ssrf_proxy_network - default + # Certbot service + # use `docker-compose --profile certbot up` to start the certbot service. + certbot: + image: certbot/certbot + profiles: + - certbot + volumes: + - ./volumes/certbot/conf:/etc/letsencrypt + - ./volumes/certbot/www:/var/www/html + - ./volumes/certbot/logs:/var/log/letsencrypt + - ./volumes/certbot/conf/live:/etc/letsencrypt/live + - ./certbot/update-cert.template.txt:/update-cert.template.txt + - ./certbot/docker-entrypoint.sh:/docker-entrypoint.sh + environment: + - CERTBOT_EMAIL=${CERTBOT_EMAIL} + - CERTBOT_DOMAIN=${CERTBOT_DOMAIN} + - CERTBOT_OPTIONS=${CERTBOT_OPTIONS:-} + entrypoint: [ "/docker-entrypoint.sh" ] + command: ["tail", "-f", "/dev/null"] + # The nginx reverse proxy. # used for reverse proxying the API service and Web service. nginx: @@ -306,7 +326,10 @@ services: - ./nginx/https.conf.template:/etc/nginx/https.conf.template - ./nginx/conf.d:/etc/nginx/conf.d - ./nginx/docker-entrypoint.sh:/docker-entrypoint-mount.sh - - ./nginx/ssl:/etc/ssl + - ./nginx/ssl:/etc/ssl # cert dir (legacy) + - ./volumes/certbot/conf/live:/etc/letsencrypt/live # cert dir (with certbot container) + - ./volumes/certbot/conf:/etc/letsencrypt + - ./volumes/certbot/www:/var/www/html entrypoint: [ "sh", "-c", "cp /docker-entrypoint-mount.sh /docker-entrypoint.sh && sed -i 's/\r$$//' /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh && /docker-entrypoint.sh" ] environment: NGINX_SERVER_NAME: ${NGINX_SERVER_NAME:-_} @@ -323,6 +346,8 @@ services: NGINX_KEEPALIVE_TIMEOUT: ${NGINX_KEEPALIVE_TIMEOUT:-65} NGINX_PROXY_READ_TIMEOUT: ${NGINX_PROXY_READ_TIMEOUT:-3600s} NGINX_PROXY_SEND_TIMEOUT: ${NGINX_PROXY_SEND_TIMEOUT:-3600s} + NGINX_ENABLE_CERTBOT_CHALLENGE: ${NGINX_ENABLE_CERTBOT_CHALLENGE:-false} + CERTBOT_DOMAIN: ${CERTBOT_DOMAIN:-} depends_on: - api - web @@ -453,7 +478,7 @@ services: - ./volumes/milvus/etcd:/etcd command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd healthcheck: - test: ["CMD", "etcdctl", "endpoint", "health"] + test: [ "CMD", "etcdctl", "endpoint", "health" ] interval: 30s timeout: 20s retries: 3 @@ -472,7 +497,7 @@ services: - ./volumes/milvus/minio:/minio_data command: minio server /minio_data --console-address ":9001" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ] interval: 30s timeout: 20s retries: 3 @@ -484,7 +509,7 @@ services: image: milvusdb/milvus:v2.3.1 profiles: - milvus - command: ["milvus", "run", "standalone"] + command: [ "milvus", "run", "standalone" ] environment: ETCD_ENDPOINTS: ${ETCD_ENDPOINTS:-etcd:2379} MINIO_ADDRESS: ${MINIO_ADDRESS:-minio:9000} @@ -492,7 +517,7 @@ services: volumes: - ./volumes/milvus/milvus:/var/lib/milvus healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] + test: [ "CMD", "curl", "-f", "http://localhost:9091/healthz" ] interval: 30s start_period: 90s timeout: 20s diff --git a/docker/nginx/conf.d/default.conf.template b/docker/nginx/conf.d/default.conf.template index 9f6e99af51..9691122cea 100644 --- a/docker/nginx/conf.d/default.conf.template +++ b/docker/nginx/conf.d/default.conf.template @@ -29,6 +29,9 @@ server { include proxy.conf; } + # placeholder for acme challenge location + ${ACME_CHALLENGE_LOCATION} + # placeholder for https config defined in https.conf.template ${HTTPS_CONFIG} } diff --git a/docker/nginx/docker-entrypoint.sh b/docker/nginx/docker-entrypoint.sh index df432a0213..d343cb3efa 100755 --- a/docker/nginx/docker-entrypoint.sh +++ b/docker/nginx/docker-entrypoint.sh @@ -1,6 +1,19 @@ #!/bin/bash if [ "${NGINX_HTTPS_ENABLED}" = "true" ]; then + # Check if the certificate and key files for the specified domain exist + if [ -n "${CERTBOT_DOMAIN}" ] && \ + [ -f "/etc/letsencrypt/live/${CERTBOT_DOMAIN}/${NGINX_SSL_CERT_FILENAME}" ] && \ + [ -f "/etc/letsencrypt/live/${CERTBOT_DOMAIN}/${NGINX_SSL_CERT_KEY_FILENAME}" ]; then + SSL_CERTIFICATE_PATH="/etc/letsencrypt/live/${CERTBOT_DOMAIN}/${NGINX_SSL_CERT_FILENAME}" + SSL_CERTIFICATE_KEY_PATH="/etc/letsencrypt/live/${CERTBOT_DOMAIN}/${NGINX_SSL_CERT_KEY_FILENAME}" + else + SSL_CERTIFICATE_PATH="/etc/ssl/${NGINX_SSL_CERT_FILENAME}" + SSL_CERTIFICATE_KEY_PATH="/etc/ssl/${NGINX_SSL_CERT_KEY_FILENAME}" + fi + export SSL_CERTIFICATE_PATH + export SSL_CERTIFICATE_KEY_PATH + # set the HTTPS_CONFIG environment variable to the content of the https.conf.template HTTPS_CONFIG=$(envsubst < /etc/nginx/https.conf.template) export HTTPS_CONFIG @@ -8,6 +21,13 @@ if [ "${NGINX_HTTPS_ENABLED}" = "true" ]; then envsubst '${HTTPS_CONFIG}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf fi +if [ "${NGINX_ENABLE_CERTBOT_CHALLENGE}" = "true" ]; then + ACME_CHALLENGE_LOCATION='location /.well-known/acme-challenge/ { root /var/www/html; }' +else + ACME_CHALLENGE_LOCATION='' +fi +export ACME_CHALLENGE_LOCATION + env_vars=$(printenv | cut -d= -f1 | sed 's/^/$/g' | paste -sd, -) envsubst "$env_vars" < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf diff --git a/docker/nginx/https.conf.template b/docker/nginx/https.conf.template index 12a6f56e3b..95ea36f463 100644 --- a/docker/nginx/https.conf.template +++ b/docker/nginx/https.conf.template @@ -1,8 +1,8 @@ # Please do not directly edit this file. Instead, modify the .env variables related to NGINX configuration. listen ${NGINX_SSL_PORT} ssl; -ssl_certificate ./../ssl/${NGINX_SSL_CERT_FILENAME}; -ssl_certificate_key ./../ssl/${NGINX_SSL_CERT_KEY_FILENAME}; +ssl_certificate ${SSL_CERTIFICATE_PATH}; +ssl_certificate_key ${SSL_CERTIFICATE_KEY_PATH}; ssl_protocols ${NGINX_SSL_PROTOCOLS}; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; From 8904745129a88d9a55f31c9cf20edc164778e2ee Mon Sep 17 00:00:00 2001 From: kimjion <45935338+kimjion@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:55:32 +0800 Subject: [PATCH 12/19] feat: tag filter adapte to scrolling (#6819) --- web/app/components/base/tag-management/filter.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/app/components/base/tag-management/filter.tsx b/web/app/components/base/tag-management/filter.tsx index 560f238262..e7cfbfd687 100644 --- a/web/app/components/base/tag-management/filter.tsx +++ b/web/app/components/base/tag-management/filter.tsx @@ -109,11 +109,11 @@ const TagFilter: FC = ({ -
+
-
+
{filteredTagList.map(tag => (
Date: Wed, 31 Jul 2024 13:34:44 +0700 Subject: [PATCH 13/19] feat: support Celery auto-scale (#6249) Co-authored-by: takatost --- api/docker/entrypoint.sh | 15 ++++++++++++++- docker/.env.example | 26 ++++++++++++++++++++++++++ docker/docker-compose.yaml | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/api/docker/entrypoint.sh b/api/docker/entrypoint.sh index a53d84c6e9..9cf5c505d1 100755 --- a/api/docker/entrypoint.sh +++ b/api/docker/entrypoint.sh @@ -8,8 +8,21 @@ if [[ "${MIGRATION_ENABLED}" == "true" ]]; then fi if [[ "${MODE}" == "worker" ]]; then - exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} -c ${CELERY_WORKER_AMOUNT:-1} --loglevel INFO \ + + # Get the number of available CPU cores + if [ "${CELERY_AUTO_SCALE,,}" = "true" ]; then + # Set MAX_WORKERS to the number of available cores if not specified + AVAILABLE_CORES=$(nproc) + MAX_WORKERS=${CELERY_MAX_WORKERS:-$AVAILABLE_CORES} + MIN_WORKERS=${CELERY_MIN_WORKERS:-1} + CONCURRENCY_OPTION="--autoscale=${MAX_WORKERS},${MIN_WORKERS}" + else + CONCURRENCY_OPTION="-c ${CELERY_WORKER_AMOUNT:-1}" + fi + + exec celery -A app.celery worker -P ${CELERY_WORKER_CLASS:-gevent} $CONCURRENCY_OPTION --loglevel INFO \ -Q ${CELERY_QUEUES:-dataset,generation,mail,ops_trace,app_deletion} + elif [[ "${MODE}" == "beat" ]]; then exec celery -A app.celery beat --loglevel INFO else diff --git a/docker/.env.example b/docker/.env.example index fa0b0d6950..b4a55bbba5 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -124,10 +124,36 @@ GUNICORN_TIMEOUT=360 # The number of Celery workers. The default is 1, and can be set as needed. CELERY_WORKER_AMOUNT= +# Flag indicating whether to enable autoscaling of Celery workers. +# +# Autoscaling is useful when tasks are CPU intensive and can be dynamically +# allocated and deallocated based on the workload. +# +# When autoscaling is enabled, the maximum and minimum number of workers can +# be specified. The autoscaling algorithm will dynamically adjust the number +# of workers within the specified range. +# +# Default is false (i.e., autoscaling is disabled). +# +# Example: +# CELERY_AUTO_SCALE=true +CELERY_AUTO_SCALE=false + +# The maximum number of Celery workers that can be autoscaled. +# This is optional and only used when autoscaling is enabled. +# Default is not set. +CELERY_MAX_WORKERS= + +# The minimum number of Celery workers that can be autoscaled. +# This is optional and only used when autoscaling is enabled. +# Default is not set. +CELERY_MIN_WORKERS= + # API Tool configuration API_TOOL_DEFAULT_CONNECT_TIMEOUT=10 API_TOOL_DEFAULT_READ_TIMEOUT=60 + # ------------------------------ # Database Configuration # The database uses PostgreSQL. Please use the public schema. diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 6a3d61b309..de7afa8efb 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -22,6 +22,9 @@ x-shared-env: &shared-api-worker-env CELERY_WORKER_CLASS: ${CELERY_WORKER_CLASS:-} GUNICORN_TIMEOUT: ${GUNICORN_TIMEOUT:-360} CELERY_WORKER_AMOUNT: ${CELERY_WORKER_AMOUNT:-} + CELERY_AUTO_SCALE: ${CELERY_AUTO_SCALE:-false} + CELERY_MAX_WORKERS: ${CELERY_MAX_WORKERS:-} + CELERY_MIN_WORKERS: ${CELERY_MIN_WORKERS:-} API_TOOL_DEFAULT_CONNECT_TIMEOUT: ${API_TOOL_DEFAULT_CONNECT_TIMEOUT:-10} API_TOOL_DEFAULT_READ_TIMEOUT: ${API_TOOL_DEFAULT_READ_TIMEOUT:-60} DB_USERNAME: ${DB_USERNAME:-postgres} From c23aa50bea16f11c33096716b6143b1c322ba020 Mon Sep 17 00:00:00 2001 From: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:41:42 +0800 Subject: [PATCH 14/19] Add AWS builtin Tools (#6721) Co-authored-by: Yuanbo Li Co-authored-by: crazywoola <427733928@qq.com> --- .../provider/builtin/aws/_assets/icon.svg | 9 ++ api/core/tools/provider/builtin/aws/aws.py | 25 ++++ api/core/tools/provider/builtin/aws/aws.yaml | 15 ++ .../builtin/aws/tools/apply_guardrail.py | 83 +++++++++++ .../builtin/aws/tools/apply_guardrail.yaml | 56 ++++++++ .../aws/tools/lambda_translate_utils.py | 88 ++++++++++++ .../aws/tools/lambda_translate_utils.yaml | 134 ++++++++++++++++++ .../aws/tools/sagemaker_text_rerank.py | 86 +++++++++++ .../aws/tools/sagemaker_text_rerank.yaml | 82 +++++++++++ 9 files changed, 578 insertions(+) create mode 100644 api/core/tools/provider/builtin/aws/_assets/icon.svg create mode 100644 api/core/tools/provider/builtin/aws/aws.py create mode 100644 api/core/tools/provider/builtin/aws/aws.yaml create mode 100644 api/core/tools/provider/builtin/aws/tools/apply_guardrail.py create mode 100644 api/core/tools/provider/builtin/aws/tools/apply_guardrail.yaml create mode 100644 api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.py create mode 100644 api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.yaml create mode 100644 api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.py create mode 100644 api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.yaml diff --git a/api/core/tools/provider/builtin/aws/_assets/icon.svg b/api/core/tools/provider/builtin/aws/_assets/icon.svg new file mode 100644 index 0000000000..ecfcfc08d4 --- /dev/null +++ b/api/core/tools/provider/builtin/aws/_assets/icon.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/api/core/tools/provider/builtin/aws/aws.py b/api/core/tools/provider/builtin/aws/aws.py new file mode 100644 index 0000000000..13ede96015 --- /dev/null +++ b/api/core/tools/provider/builtin/aws/aws.py @@ -0,0 +1,25 @@ +from core.tools.errors import ToolProviderCredentialValidationError +from core.tools.provider.builtin.aws.tools.sagemaker_text_rerank import SageMakerReRankTool +from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController + + +class SageMakerProvider(BuiltinToolProviderController): + def _validate_credentials(self, credentials: dict) -> None: + try: + SageMakerReRankTool().fork_tool_runtime( + runtime={ + "credentials": credentials, + } + ).invoke( + user_id='', + tool_parameters={ + "sagemaker_endpoint" : "", + "query": "misaka mikoto", + "candidate_texts" : "hello$$$hello world", + "topk" : 5, + "aws_region" : "" + }, + ) + except Exception as e: + raise ToolProviderCredentialValidationError(str(e)) + \ No newline at end of file diff --git a/api/core/tools/provider/builtin/aws/aws.yaml b/api/core/tools/provider/builtin/aws/aws.yaml new file mode 100644 index 0000000000..847c6824a5 --- /dev/null +++ b/api/core/tools/provider/builtin/aws/aws.yaml @@ -0,0 +1,15 @@ +identity: + author: AWS + name: aws + label: + en_US: AWS + zh_Hans: 亚马逊云科技 + pt_BR: AWS + description: + en_US: Services on AWS. + zh_Hans: 亚马逊云科技的各类服务 + pt_BR: Services on AWS. + icon: icon.svg + tags: + - search +credentials_for_provider: diff --git a/api/core/tools/provider/builtin/aws/tools/apply_guardrail.py b/api/core/tools/provider/builtin/aws/tools/apply_guardrail.py new file mode 100644 index 0000000000..9c006733bd --- /dev/null +++ b/api/core/tools/provider/builtin/aws/tools/apply_guardrail.py @@ -0,0 +1,83 @@ +import json +import logging +from typing import Any, Union + +import boto3 +from pydantic import BaseModel, Field + +from core.tools.entities.tool_entities import ToolInvokeMessage +from core.tools.tool.builtin_tool import BuiltinTool + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +class GuardrailParameters(BaseModel): + guardrail_id: str = Field(..., description="The identifier of the guardrail") + guardrail_version: str = Field(..., description="The version of the guardrail") + source: str = Field(..., description="The source of the content") + text: str = Field(..., description="The text to apply the guardrail to") + aws_region: str = Field(default="us-east-1", description="AWS region for the Bedrock client") + +class ApplyGuardrailTool(BuiltinTool): + def _invoke(self, + user_id: str, + tool_parameters: dict[str, Any] + ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]: + """ + Invoke the ApplyGuardrail tool + """ + try: + # Validate and parse input parameters + params = GuardrailParameters(**tool_parameters) + + # Initialize AWS client + bedrock_client = boto3.client('bedrock-runtime', region_name=params.aws_region) + + # Apply guardrail + response = bedrock_client.apply_guardrail( + guardrailIdentifier=params.guardrail_id, + guardrailVersion=params.guardrail_version, + source=params.source, + content=[{"text": {"text": params.text}}] + ) + + # Check for empty response + if not response: + return self.create_text_message(text="Received empty response from AWS Bedrock.") + + # Process the result + action = response.get("action", "No action specified") + outputs = response.get("outputs", []) + output = outputs[0].get("text", "No output received") if outputs else "No output received" + assessments = response.get("assessments", []) + + # Format assessments + formatted_assessments = [] + for assessment in assessments: + for policy_type, policy_data in assessment.items(): + if isinstance(policy_data, dict) and 'topics' in policy_data: + for topic in policy_data['topics']: + formatted_assessments.append(f"Policy: {policy_type}, Topic: {topic['name']}, Type: {topic['type']}, Action: {topic['action']}") + else: + formatted_assessments.append(f"Policy: {policy_type}, Data: {policy_data}") + + result = f"Action: {action}\n " + result += f"Output: {output}\n " + if formatted_assessments: + result += "Assessments:\n " + "\n ".join(formatted_assessments) + "\n " +# result += f"Full response: {json.dumps(response, indent=2, ensure_ascii=False)}" + + return self.create_text_message(text=result) + + except boto3.exceptions.BotoCoreError as e: + error_message = f'AWS service error: {str(e)}' + logger.error(error_message, exc_info=True) + return self.create_text_message(text=error_message) + except json.JSONDecodeError as e: + error_message = f'JSON parsing error: {str(e)}' + logger.error(error_message, exc_info=True) + return self.create_text_message(text=error_message) + except Exception as e: + error_message = f'An unexpected error occurred: {str(e)}' + logger.error(error_message, exc_info=True) + return self.create_text_message(text=error_message) diff --git a/api/core/tools/provider/builtin/aws/tools/apply_guardrail.yaml b/api/core/tools/provider/builtin/aws/tools/apply_guardrail.yaml new file mode 100644 index 0000000000..2b7c8abb44 --- /dev/null +++ b/api/core/tools/provider/builtin/aws/tools/apply_guardrail.yaml @@ -0,0 +1,56 @@ +identity: + name: apply_guardrail + author: AWS + label: + en_US: Content Moderation Guardrails + zh_Hans: 内容审查护栏 +description: + human: + en_US: Content Moderation Guardrails utilizes the ApplyGuardrail API, a feature of Guardrails for Amazon Bedrock. This API is capable of evaluating input prompts and model responses for all Foundation Models (FMs), including those on Amazon Bedrock, custom FMs, and third-party FMs. By implementing this functionality, organizations can achieve centralized governance across all their generative AI applications, thereby enhancing control and consistency in content moderation. + zh_Hans: 内容审查护栏采用 Guardrails for Amazon Bedrock 功能中的 ApplyGuardrail API 。ApplyGuardrail 可以评估所有基础模型(FMs)的输入提示和模型响应,包括 Amazon Bedrock 上的 FMs、自定义 FMs 和第三方 FMs。通过实施这一功能, 组织可以在所有生成式 AI 应用程序中实现集中化的治理,从而增强内容审核的控制力和一致性。 + llm: Content Moderation Guardrails utilizes the ApplyGuardrail API, a feature of Guardrails for Amazon Bedrock. This API is capable of evaluating input prompts and model responses for all Foundation Models (FMs), including those on Amazon Bedrock, custom FMs, and third-party FMs. By implementing this functionality, organizations can achieve centralized governance across all their generative AI applications, thereby enhancing control and consistency in content moderation. +parameters: + - name: guardrail_id + type: string + required: true + label: + en_US: Guardrail ID + zh_Hans: Guardrail ID + human_description: + en_US: Please enter the ID of the Guardrail that has already been created on Amazon Bedrock, for example 'qk5nk0e4b77b'. + zh_Hans: 请输入已经在 Amazon Bedrock 上创建好的 Guardrail ID, 例如 'qk5nk0e4b77b'. + llm_description: Please enter the ID of the Guardrail that has already been created on Amazon Bedrock, for example 'qk5nk0e4b77b'. + form: form + - name: guardrail_version + type: string + required: true + label: + en_US: Guardrail Version Number + zh_Hans: Guardrail 版本号码 + human_description: + en_US: Please enter the published version of the Guardrail ID that has already been created on Amazon Bedrock. This is typically a version number, such as 2. + zh_Hans: 请输入已经在Amazon Bedrock 上创建好的Guardrail ID发布的版本, 通常使用版本号, 例如2. + llm_description: Please enter the published version of the Guardrail ID that has already been created on Amazon Bedrock. This is typically a version number, such as 2. + form: form + - name: source + type: string + required: true + label: + en_US: Content Source (INPUT or OUTPUT) + zh_Hans: 内容来源 (INPUT or OUTPUT) + human_description: + en_US: The source of data used in the request to apply the guardrail. Valid Values "INPUT | OUTPUT" + zh_Hans: 用于应用护栏的请求中所使用的数据来源。有效值为 "INPUT | OUTPUT" + llm_description: The source of data used in the request to apply the guardrail. Valid Values "INPUT | OUTPUT" + form: form + - name: text + type: string + required: true + label: + en_US: Content to be reviewed + zh_Hans: 待审查内容 + human_description: + en_US: The content used for requesting guardrail review, which can be either user input or LLM output. + zh_Hans: 用于请求护栏审查的内容,可以是用户输入或 LLM 输出。 + llm_description: The content used for requesting guardrail review, which can be either user input or LLM output. + form: llm diff --git a/api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.py b/api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.py new file mode 100644 index 0000000000..005ba3deb5 --- /dev/null +++ b/api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.py @@ -0,0 +1,88 @@ +import json +from typing import Any, Union + +import boto3 + +from core.tools.entities.tool_entities import ToolInvokeMessage +from core.tools.tool.builtin_tool import BuiltinTool + + +class LambdaTranslateUtilsTool(BuiltinTool): + lambda_client: Any = None + + def _invoke_lambda(self, text_content, src_lang, dest_lang, model_id, dictionary_name, request_type, lambda_name): + msg = { + "src_content":text_content, + "src_lang": src_lang, + "dest_lang":dest_lang, + "dictionary_id": dictionary_name, + "request_type" : request_type, + "model_id" : model_id + } + + invoke_response = self.lambda_client.invoke(FunctionName=lambda_name, + InvocationType='RequestResponse', + Payload=json.dumps(msg)) + response_body = invoke_response['Payload'] + + response_str = response_body.read().decode("unicode_escape") + + return response_str + + def _invoke(self, + user_id: str, + tool_parameters: dict[str, Any], + ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]: + """ + invoke tools + """ + line = 0 + try: + if not self.lambda_client: + aws_region = tool_parameters.get('aws_region') + if aws_region: + self.lambda_client = boto3.client("lambda", region_name=aws_region) + else: + self.lambda_client = boto3.client("lambda") + + line = 1 + text_content = tool_parameters.get('text_content', '') + if not text_content: + return self.create_text_message('Please input text_content') + + line = 2 + src_lang = tool_parameters.get('src_lang', '') + if not src_lang: + return self.create_text_message('Please input src_lang') + + line = 3 + dest_lang = tool_parameters.get('dest_lang', '') + if not dest_lang: + return self.create_text_message('Please input dest_lang') + + line = 4 + lambda_name = tool_parameters.get('lambda_name', '') + if not lambda_name: + return self.create_text_message('Please input lambda_name') + + line = 5 + request_type = tool_parameters.get('request_type', '') + if not request_type: + return self.create_text_message('Please input request_type') + + line = 6 + model_id = tool_parameters.get('model_id', '') + if not model_id: + return self.create_text_message('Please input model_id') + + line = 7 + dictionary_name = tool_parameters.get('dictionary_name', '') + if not dictionary_name: + return self.create_text_message('Please input dictionary_name') + + result = self._invoke_lambda(text_content, src_lang, dest_lang, model_id, dictionary_name, request_type, lambda_name) + + return self.create_text_message(text=result) + + except Exception as e: + return self.create_text_message(f'Exception {str(e)}, line : {line}') diff --git a/api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.yaml b/api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.yaml new file mode 100644 index 0000000000..a35c9f49fb --- /dev/null +++ b/api/core/tools/provider/builtin/aws/tools/lambda_translate_utils.yaml @@ -0,0 +1,134 @@ +identity: + name: lambda_translate_utils + author: AWS + label: + en_US: TranslateTool + zh_Hans: 翻译工具 + pt_BR: TranslateTool + icon: icon.svg +description: + human: + en_US: A util tools for LLM translation, extra deployment is needed on AWS. Please refer Github Repo - https://github.com/ybalbert001/dynamodb-rag + zh_Hans: 大语言模型翻译工具(专词映射获取),需要在AWS上进行额外部署,可参考Github Repo - https://github.com/ybalbert001/dynamodb-rag + pt_BR: A util tools for LLM translation, specfic Lambda Function deployment is needed on AWS. Please refer Github Repo - https://github.com/ybalbert001/dynamodb-rag + llm: A util tools for translation. +parameters: + - name: text_content + type: string + required: true + label: + en_US: source content for translation + zh_Hans: 待翻译原文 + pt_BR: source content for translation + human_description: + en_US: source content for translation + zh_Hans: 待翻译原文 + pt_BR: source content for translation + llm_description: source content for translation + form: llm + - name: src_lang + type: string + required: true + label: + en_US: source language code + zh_Hans: 原文语言代号 + pt_BR: source language code + human_description: + en_US: source language code + zh_Hans: 原文语言代号 + pt_BR: source language code + llm_description: source language code + form: llm + - name: dest_lang + type: string + required: true + label: + en_US: target language code + zh_Hans: 目标语言代号 + pt_BR: target language code + human_description: + en_US: target language code + zh_Hans: 目标语言代号 + pt_BR: target language code + llm_description: target language code + form: llm + - name: aws_region + type: string + required: false + label: + en_US: region of Lambda + zh_Hans: Lambda 所在的region + pt_BR: region of Lambda + human_description: + en_US: region of Lambda + zh_Hans: Lambda 所在的region + pt_BR: region of Lambda + llm_description: region of Lambda + form: form + - name: model_id + type: string + required: false + default: anthropic.claude-3-sonnet-20240229-v1:0 + label: + en_US: LLM model_id in bedrock + zh_Hans: bedrock上的大语言模型model_id + pt_BR: LLM model_id in bedrock + human_description: + en_US: LLM model_id in bedrock + zh_Hans: bedrock上的大语言模型model_id + pt_BR: LLM model_id in bedrock + llm_description: LLM model_id in bedrock + form: form + - name: dictionary_name + type: string + required: false + label: + en_US: dictionary name for term mapping + zh_Hans: 专词映射表名称 + pt_BR: dictionary name for term mapping + human_description: + en_US: dictionary name for term mapping + zh_Hans: 专词映射表名称 + pt_BR: dictionary name for term mapping + llm_description: dictionary name for term mapping + form: form + - name: request_type + type: select + required: false + label: + en_US: request type + zh_Hans: 请求类型 + pt_BR: request type + human_description: + en_US: request type + zh_Hans: 请求类型 + pt_BR: request type + default: term_mapping + options: + - value: term_mapping + label: + en_US: term_mapping + zh_Hans: 专词映射 + - value: segment_only + label: + en_US: segment_only + zh_Hans: 仅切词 + - value: translate + label: + en_US: translate + zh_Hans: 翻译内容 + form: form + - name: lambda_name + type: string + default: "translate_tool" + required: true + label: + en_US: AWS Lambda for term mapping retrieval + zh_Hans: 专词召回映射 - AWS Lambda + pt_BR: lambda name for term mapping retrieval + human_description: + en_US: AWS Lambda for term mapping retrieval + zh_Hans: 专词召回映射 - AWS Lambda + pt_BR: AWS Lambda for term mapping retrieval + llm_description: AWS Lambda for term mapping retrieval + form: form diff --git a/api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.py b/api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.py new file mode 100644 index 0000000000..d4bc446e5b --- /dev/null +++ b/api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.py @@ -0,0 +1,86 @@ +import json +from typing import Any, Union + +import boto3 + +from core.tools.entities.tool_entities import ToolInvokeMessage +from core.tools.tool.builtin_tool import BuiltinTool + + +class SageMakerReRankTool(BuiltinTool): + sagemaker_client: Any = None + sagemaker_endpoint:str = None + topk:int = None + + def _sagemaker_rerank(self, query_input: str, docs: list[str], rerank_endpoint:str): + inputs = [query_input]*len(docs) + response_model = self.sagemaker_client.invoke_endpoint( + EndpointName=rerank_endpoint, + Body=json.dumps( + { + "inputs": inputs, + "docs": docs + } + ), + ContentType="application/json", + ) + json_str = response_model['Body'].read().decode('utf8') + json_obj = json.loads(json_str) + scores = json_obj['scores'] + return scores if isinstance(scores, list) else [scores] + + def _invoke(self, + user_id: str, + tool_parameters: dict[str, Any], + ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]: + """ + invoke tools + """ + line = 0 + try: + if not self.sagemaker_client: + aws_region = tool_parameters.get('aws_region') + if aws_region: + self.sagemaker_client = boto3.client("sagemaker-runtime", region_name=aws_region) + else: + self.sagemaker_client = boto3.client("sagemaker-runtime") + + line = 1 + if not self.sagemaker_endpoint: + self.sagemaker_endpoint = tool_parameters.get('sagemaker_endpoint') + + line = 2 + if not self.topk: + self.topk = tool_parameters.get('topk', 5) + + line = 3 + query = tool_parameters.get('query', '') + if not query: + return self.create_text_message('Please input query') + + line = 4 + candidate_texts = tool_parameters.get('candidate_texts') + if not candidate_texts: + return self.create_text_message('Please input candidate_texts') + + line = 5 + candidate_docs = json.loads(candidate_texts) + docs = [ item.get('content') for item in candidate_docs ] + + line = 6 + scores = self._sagemaker_rerank(query_input=query, docs=docs, rerank_endpoint=self.sagemaker_endpoint) + + line = 7 + for idx in range(len(candidate_docs)): + candidate_docs[idx]["score"] = scores[idx] + + line = 8 + sorted_candidate_docs = sorted(candidate_docs, key=lambda x: x['score'], reverse=True) + + line = 9 + results_str = json.dumps(sorted_candidate_docs[:self.topk], ensure_ascii=False) + return self.create_text_message(text=results_str) + + except Exception as e: + return self.create_text_message(f'Exception {str(e)}, line : {line}') + \ No newline at end of file diff --git a/api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.yaml b/api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.yaml new file mode 100644 index 0000000000..d1dfdb9f84 --- /dev/null +++ b/api/core/tools/provider/builtin/aws/tools/sagemaker_text_rerank.yaml @@ -0,0 +1,82 @@ +identity: + name: sagemaker_text_rerank + author: AWS + label: + en_US: SagemakerRerank + zh_Hans: Sagemaker重排序 + pt_BR: SagemakerRerank + icon: icon.svg +description: + human: + en_US: A tool for performing text similarity ranking. You can find deploy notebook on Github Repo - https://github.com/aws-samples/dify-aws-tool + zh_Hans: Sagemaker重排序工具, 请参考 Github Repo - https://github.com/aws-samples/dify-aws-tool上的部署脚本 + pt_BR: A tool for performing text similarity ranking. + llm: A tool for performing text similarity ranking. You can find deploy notebook on Github Repo - https://github.com/aws-samples/dify-aws-tool +parameters: + - name: sagemaker_endpoint + type: string + required: true + label: + en_US: sagemaker endpoint for reranking + zh_Hans: 重排序的SageMaker 端点 + pt_BR: sagemaker endpoint for reranking + human_description: + en_US: sagemaker endpoint for reranking + zh_Hans: 重排序的SageMaker 端点 + pt_BR: sagemaker endpoint for reranking + llm_description: sagemaker endpoint for reranking + form: form + - name: query + type: string + required: true + label: + en_US: Query string + zh_Hans: 查询语句 + pt_BR: Query string + human_description: + en_US: key words for searching + zh_Hans: 查询关键词 + pt_BR: key words for searching + llm_description: key words for searching + form: llm + - name: candidate_texts + type: string + required: true + label: + en_US: text candidates + zh_Hans: 候选文本 + pt_BR: text candidates + human_description: + en_US: searched candidates by query + zh_Hans: 查询文本搜到候选文本 + pt_BR: searched candidates by query + llm_description: searched candidates by query + form: llm + - name: topk + type: number + required: false + form: form + label: + en_US: Limit for results count + zh_Hans: 返回个数限制 + pt_BR: Limit for results count + human_description: + en_US: Limit for results count + zh_Hans: 返回个数限制 + pt_BR: Limit for results count + min: 1 + max: 10 + default: 5 + - name: aws_region + type: string + required: false + label: + en_US: region of sagemaker endpoint + zh_Hans: SageMaker 端点所在的region + pt_BR: region of sagemaker endpoint + human_description: + en_US: region of sagemaker endpoint + zh_Hans: SageMaker 端点所在的region + pt_BR: region of sagemaker endpoint + llm_description: region of sagemaker endpoint + form: form From dd64e65ea09ae2575fac1b838ec3d450de6426e6 Mon Sep 17 00:00:00 2001 From: NFish Date: Wed, 31 Jul 2024 15:11:07 +0800 Subject: [PATCH 15/19] fix: edit segment missing space between buttons (#6826) Co-authored-by: xc Dou --- web/app/components/datasets/documents/detail/completed/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/web/app/components/datasets/documents/detail/completed/index.tsx b/web/app/components/datasets/documents/detail/completed/index.tsx index 80973ee631..f2addac2e2 100644 --- a/web/app/components/datasets/documents/detail/completed/index.tsx +++ b/web/app/components/datasets/documents/detail/completed/index.tsx @@ -142,6 +142,7 @@ const SegmentDetailComponent: FC = ({