import { useTranslate } from '@/hooks/common-hooks'; import { useFetchAllAddedModels } from '@/hooks/use-llm-request'; import { cn } from '@/lib/utils'; import { camelCase } from 'lodash'; import { ReactNode, useMemo } from 'react'; import { useFormContext } from 'react-hook-form'; import { MinerUOptionsFormField } from './mineru-options-form-field'; import { buildModelTree } from './model-tree-select'; import { PaddleOCROptionsFormField } from './paddleocr-options-form-field'; import { TreeSelect, TreeSelectNode } from './tree-select'; import { FormControl, FormField, FormItem, FormLabel, FormMessage, } from './ui/form'; export const enum ParseDocumentType { DeepDOC = 'DeepDOC', PlainText = 'Plain Text', Docling = 'Docling', OpenDataLoader = 'OpenDataLoader', TCADPParser = 'TCADP Parser', } export function LayoutRecognizeFormField({ name = 'parser_config.layout_recognize', horizontal = true, optionsWithoutLLM, label, showMineruOptions = true, showPaddleocrOptions = true, testId, ownerTenantId, }: { name?: string; horizontal?: boolean; optionsWithoutLLM?: { value: string; label: string }[]; label?: ReactNode; showMineruOptions?: boolean; showPaddleocrOptions?: boolean; testId?: string; ownerTenantId?: string; }) { const form = useFormContext(); const { t } = useTranslate('knowledgeDetails'); const { data: allAddedModels } = useFetchAllAddedModels( undefined, ownerTenantId, ); const treeData = useMemo(() => { const list = optionsWithoutLLM ? optionsWithoutLLM : [ ParseDocumentType.DeepDOC, ParseDocumentType.PlainText, ParseDocumentType.Docling, ParseDocumentType.OpenDataLoader, ParseDocumentType.TCADPParser, ].map((x) => ({ label: x === ParseDocumentType.PlainText ? t(camelCase(x)) : x, value: x, })); const prependNodes: TreeSelectNode[] = list.map((x) => ({ id: x.value, title: x.label, })); const modelTree = buildModelTree( allAddedModels, ['image2text', 'ocr'], (node) => (