mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-02 03:07:59 +08:00
33 lines
1012 B
TypeScript
33 lines
1012 B
TypeScript
import { useCallback } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
export const useKnowledge = () => {
|
|
const { t } = useTranslation()
|
|
|
|
const formatIndexingTechnique = useCallback((indexingTechnique: string) => {
|
|
return t(`dataset.indexingTechnique.${indexingTechnique}`)
|
|
}, [t])
|
|
|
|
const formatIndexingMethod = useCallback((indexingMethod: string, isEco?: boolean) => {
|
|
if (isEco)
|
|
return t('dataset.indexingMethod.invertedIndex')
|
|
|
|
return t(`dataset.indexingMethod.${indexingMethod}`)
|
|
}, [t])
|
|
|
|
const formatIndexingTechniqueAndMethod = useCallback((indexingTechnique: string, indexingMethod: string) => {
|
|
let result = formatIndexingTechnique(indexingTechnique)
|
|
|
|
if (indexingMethod)
|
|
result += ` · ${formatIndexingMethod(indexingMethod, indexingTechnique === 'economy')}`
|
|
|
|
return result
|
|
}, [formatIndexingTechnique, formatIndexingMethod])
|
|
|
|
return {
|
|
formatIndexingTechnique,
|
|
formatIndexingMethod,
|
|
formatIndexingTechniqueAndMethod,
|
|
}
|
|
}
|