mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
d069c668f8
Co-authored-by: StyleZhang <jasonapring2015@outlook.com> Co-authored-by: Garfield Dai <dai.hai@foxmail.com> Co-authored-by: chenhe <guchenhe@gmail.com> Co-authored-by: jyong <jyong@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Yeuoly <admin@srmxy.cn>
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { RETRIEVE_METHOD, type RetrievalConfig } from '@/types/app'
|
|
import type {
|
|
DefaultModelResponse,
|
|
Model,
|
|
} from '@/app/components/header/account-setting/model-provider-page/declarations'
|
|
|
|
export const isReRankModelSelected = ({
|
|
rerankDefaultModel,
|
|
isRerankDefaultModelVaild,
|
|
retrievalConfig,
|
|
rerankModelList,
|
|
indexMethod,
|
|
}: {
|
|
rerankDefaultModel?: DefaultModelResponse
|
|
isRerankDefaultModelVaild: boolean
|
|
retrievalConfig: RetrievalConfig
|
|
rerankModelList: Model[]
|
|
indexMethod?: string
|
|
}) => {
|
|
const rerankModelSelected = (() => {
|
|
if (retrievalConfig.reranking_model?.reranking_model_name) {
|
|
const provider = rerankModelList.find(({ provider }) => provider === retrievalConfig.reranking_model?.reranking_provider_name)
|
|
|
|
return provider?.models.find(({ model }) => model === retrievalConfig.reranking_model?.reranking_model_name)
|
|
}
|
|
|
|
if (isRerankDefaultModelVaild)
|
|
return !!rerankDefaultModel
|
|
|
|
return false
|
|
})()
|
|
|
|
if (
|
|
indexMethod === 'high_quality'
|
|
&& (retrievalConfig.reranking_enable || retrievalConfig.search_method === RETRIEVE_METHOD.hybrid)
|
|
&& !rerankModelSelected
|
|
)
|
|
return false
|
|
|
|
return true
|
|
}
|
|
|
|
export const ensureRerankModelSelected = ({
|
|
rerankDefaultModel,
|
|
indexMethod,
|
|
retrievalConfig,
|
|
}: {
|
|
rerankDefaultModel: DefaultModelResponse
|
|
retrievalConfig: RetrievalConfig
|
|
indexMethod?: string
|
|
}) => {
|
|
const rerankModel = retrievalConfig.reranking_model?.reranking_model_name ? retrievalConfig.reranking_model : undefined
|
|
if (
|
|
indexMethod === 'high_quality'
|
|
&& (retrievalConfig.reranking_enable || retrievalConfig.search_method === RETRIEVE_METHOD.hybrid)
|
|
&& !rerankModel
|
|
) {
|
|
return {
|
|
...retrievalConfig,
|
|
reranking_model: {
|
|
reranking_provider_name: rerankDefaultModel.provider.provider,
|
|
reranking_model_name: rerankDefaultModel.model,
|
|
},
|
|
}
|
|
}
|
|
return retrievalConfig
|
|
}
|