Forráskód Böngészése

Fix/rerank validation issue (#10131)

Co-authored-by: Yi <yxiaoisme@gmail.com>
zxhlyh 5 hónapja
szülő
commit
2ecdc54b0b

+ 16 - 0
web/app/components/app/configuration/dataset-config/index.tsx

@@ -15,6 +15,7 @@ import { AppType } from '@/types/app'
 import type { DataSet } from '@/models/datasets'
 import {
   getMultipleRetrievalConfig,
+  getSelectedDatasetsMode,
 } from '@/app/components/workflow/nodes/knowledge-retrieval/utils'
 import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
 import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
@@ -38,6 +39,7 @@ const DatasetConfig: FC = () => {
     isAgent,
     datasetConfigs,
     setDatasetConfigs,
+    setRerankSettingModalOpen,
   } = useContext(ConfigContext)
   const formattingChangedDispatcher = useFormattingChangedDispatcher()
 
@@ -55,6 +57,20 @@ const DatasetConfig: FC = () => {
       ...(datasetConfigs as any),
       ...retrievalConfig,
     })
+    const {
+      allExternal,
+      allInternal,
+      mixtureInternalAndExternal,
+      mixtureHighQualityAndEconomic,
+      inconsistentEmbeddingModel,
+    } = getSelectedDatasetsMode(filteredDataSets)
+
+    if (
+      (allInternal && (mixtureHighQualityAndEconomic || inconsistentEmbeddingModel))
+      || mixtureInternalAndExternal
+      || allExternal
+    )
+      setRerankSettingModalOpen(true)
     formattingChangedDispatcher()
   }
 

+ 1 - 1
web/app/components/app/configuration/dataset-config/params-config/config-content.tsx

@@ -266,7 +266,7 @@ const ConfigContent: FC<Props> = ({
               <div className='mt-2'>
                 <div className='flex items-center'>
                   {
-                    selectedDatasetsMode.allEconomic && (
+                    selectedDatasetsMode.allEconomic && !selectedDatasetsMode.mixtureInternalAndExternal && (
                       <div
                         className='flex items-center'
                         onClick={handleDisabledSwitchClick}

+ 8 - 2
web/app/components/app/configuration/dataset-config/params-config/index.tsx

@@ -12,6 +12,7 @@ import { RETRIEVE_TYPE } from '@/types/app'
 import Toast from '@/app/components/base/toast'
 import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
 import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
+import { RerankingModeEnum } from '@/models/datasets'
 import type { DataSet } from '@/models/datasets'
 import type { DatasetConfigs } from '@/models/debug'
 import {
@@ -47,7 +48,10 @@ const ParamsConfig = ({
   const isValid = () => {
     let errMsg = ''
     if (tempDataSetConfigs.retrieval_model === RETRIEVE_TYPE.multiWay) {
-      if (!tempDataSetConfigs.reranking_model?.reranking_model_name && (rerankDefaultModel && !isRerankDefaultModelValid))
+      if (tempDataSetConfigs.reranking_enable
+        && tempDataSetConfigs.reranking_mode === RerankingModeEnum.RerankingModel
+        && !isRerankDefaultModelValid
+      )
         errMsg = t('appDebug.datasetConfig.rerankModelRequired')
     }
     if (errMsg) {
@@ -62,7 +66,9 @@ const ParamsConfig = ({
     if (!isValid())
       return
     const config = { ...tempDataSetConfigs }
-    if (config.retrieval_model === RETRIEVE_TYPE.multiWay && !config.reranking_model) {
+    if (config.retrieval_model === RETRIEVE_TYPE.multiWay
+      && config.reranking_mode === RerankingModeEnum.RerankingModel
+      && !config.reranking_model) {
       config.reranking_model = {
         reranking_provider_name: rerankDefaultModel?.provider?.provider,
         reranking_model_name: rerankDefaultModel?.model,

+ 8 - 2
web/app/components/app/configuration/index.tsx

@@ -253,12 +253,18 @@ const Configuration: FC = () => {
     }
     hideSelectDataSet()
     const {
-      allEconomic,
+      allExternal,
+      allInternal,
+      mixtureInternalAndExternal,
       mixtureHighQualityAndEconomic,
       inconsistentEmbeddingModel,
     } = getSelectedDatasetsMode(newDatasets)
 
-    if (allEconomic || mixtureHighQualityAndEconomic || inconsistentEmbeddingModel)
+    if (
+      (allInternal && (mixtureHighQualityAndEconomic || inconsistentEmbeddingModel))
+      || mixtureInternalAndExternal
+      || allExternal
+    )
       setRerankSettingModalOpen(true)
 
     const { datasets, retrieval_model, score_threshold_enabled, ...restConfigs } = datasetConfigs

+ 1 - 1
web/app/components/workflow/nodes/knowledge-retrieval/use-config.ts

@@ -240,7 +240,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
     if (
       (allInternal && (mixtureHighQualityAndEconomic || inconsistentEmbeddingModel))
       || mixtureInternalAndExternal
-      || (allExternal && newDatasets.length > 1)
+      || allExternal
     )
       setRerankModelOpen(true)
   }, [inputs, setInputs, payload.retrieval_mode, selectedDatasets, currentRerankModel])