refactor: update data source handling and improve internationalization support in test run panel
parent
d9ed61287d
commit
7e31da7882
@ -1,57 +1,58 @@
|
|||||||
import type { BaseConfiguration } from '@/app/components/base/form/form-scenarios/base/types'
|
import { useMemo } from 'react'
|
||||||
import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types'
|
import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types'
|
||||||
import type { FormData } from './options'
|
import { useStore } from '@/app/components/workflow/store'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { InputVarType } from '@/app/components/workflow/types'
|
||||||
|
import { usePipelineProcessingParams } from '@/service/use-pipeline'
|
||||||
|
|
||||||
|
type PartialInputVarType = InputVarType.textInput | InputVarType.number | InputVarType.select | InputVarType.checkbox
|
||||||
|
|
||||||
|
const VAR_TYPE_MAP: Record<PartialInputVarType, BaseFieldType> = {
|
||||||
|
[InputVarType.textInput]: BaseFieldType.textInput,
|
||||||
|
[InputVarType.number]: BaseFieldType.numberInput,
|
||||||
|
[InputVarType.select]: BaseFieldType.select,
|
||||||
|
[InputVarType.checkbox]: BaseFieldType.checkbox,
|
||||||
|
}
|
||||||
|
|
||||||
export const useConfigurations = () => {
|
export const useConfigurations = () => {
|
||||||
const { t } = useTranslation()
|
const pipelineId = useStore(state => state.pipelineId)
|
||||||
const maxValue = Number.parseInt(globalThis.document?.body?.getAttribute('data-public-indexing-max-segmentation-tokens-length') || '4000', 10)
|
const { data: paramsConfig } = usePipelineProcessingParams(pipelineId!)
|
||||||
|
|
||||||
|
const initialData = useMemo(() => {
|
||||||
|
const variables = paramsConfig?.variables || []
|
||||||
|
return variables.reduce((acc, item) => {
|
||||||
|
const type = VAR_TYPE_MAP[item.type as PartialInputVarType]
|
||||||
|
if (type === BaseFieldType.textInput)
|
||||||
|
acc[item.variable] = ''
|
||||||
|
if (type === BaseFieldType.numberInput)
|
||||||
|
acc[item.variable] = 0
|
||||||
|
if (type === BaseFieldType.select)
|
||||||
|
acc[item.variable] = item.options?.[0] || ''
|
||||||
|
if (type === BaseFieldType.checkbox)
|
||||||
|
acc[item.variable] = true
|
||||||
|
return acc
|
||||||
|
}, {} as Record<string, any>)
|
||||||
|
}, [paramsConfig])
|
||||||
|
|
||||||
const configurations: BaseConfiguration<FormData>[] = [
|
const configurations = useMemo(() => {
|
||||||
{
|
const variables = paramsConfig?.variables || []
|
||||||
type: BaseFieldType.textInput,
|
const configs = variables.map(item => ({
|
||||||
variable: 'separator',
|
type: VAR_TYPE_MAP[item.type as PartialInputVarType],
|
||||||
label: t('datasetCreation.stepTwo.separator'),
|
variable: item.variable,
|
||||||
required: false,
|
label: item.label,
|
||||||
showConditions: [],
|
required: item.required,
|
||||||
placeholder: t('datasetCreation.stepTwo.separatorPlaceholder'),
|
maxLength: item.max_length,
|
||||||
tooltip: t('datasetCreation.stepTwo.separatorTip'),
|
options: item.options?.map(option => ({
|
||||||
},
|
label: option,
|
||||||
{
|
value: option,
|
||||||
type: BaseFieldType.numberInput,
|
})),
|
||||||
variable: 'max_tokens',
|
showConditions: [],
|
||||||
label: t('datasetCreation.stepTwo.maxLength'),
|
default: item.default,
|
||||||
required: false,
|
}))
|
||||||
min: 1,
|
return configs
|
||||||
max: maxValue,
|
}, [paramsConfig])
|
||||||
showConditions: [],
|
|
||||||
placeholder: `≤ ${maxValue}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: BaseFieldType.numberInput,
|
|
||||||
variable: 'chunk_overlap',
|
|
||||||
label: t('datasetCreation.stepTwo.overlap'),
|
|
||||||
required: false,
|
|
||||||
min: 1,
|
|
||||||
showConditions: [],
|
|
||||||
placeholder: t('datasetCreation.stepTwo.overlap') || '',
|
|
||||||
tooltip: t('datasetCreation.stepTwo.overlapTip'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: BaseFieldType.checkbox,
|
|
||||||
variable: 'remove_extra_spaces',
|
|
||||||
label: t('datasetCreation.stepTwo.removeExtraSpaces'),
|
|
||||||
required: false,
|
|
||||||
showConditions: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: BaseFieldType.checkbox,
|
|
||||||
variable: 'remove_urls_emails',
|
|
||||||
label: t('datasetCreation.stepTwo.removeUrlEmails'),
|
|
||||||
required: false,
|
|
||||||
showConditions: [],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
return configurations
|
return {
|
||||||
|
initialData,
|
||||||
|
configurations,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue