mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-26 08:56:47 +08:00
### What problem does this PR solve? Feat: Replace antd with shadcn and delete the template node. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import { LlmModelType } from '@/constants/knowledge';
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
|
import { useSelectLlmOptionsByModelType } from '@/hooks/use-llm-request';
|
|
import { useFormContext } from 'react-hook-form';
|
|
import { z } from 'zod';
|
|
import { SelectWithSearch } from './originui/select-with-search';
|
|
import { SliderInputFormField } from './slider-input-form-field';
|
|
import {
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from './ui/form';
|
|
|
|
export const topKSchema = {
|
|
top_k: z.number().optional(),
|
|
};
|
|
|
|
export const initialTopKValue = {
|
|
top_k: 1024,
|
|
};
|
|
|
|
const RerankId = 'rerank_id';
|
|
|
|
function RerankFormField() {
|
|
const form = useFormContext();
|
|
const { t } = useTranslate('knowledgeDetails');
|
|
const allOptions = useSelectLlmOptionsByModelType();
|
|
const options = allOptions[LlmModelType.Rerank];
|
|
|
|
return (
|
|
<FormField
|
|
control={form.control}
|
|
name={RerankId}
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel tooltip={t('rerankTip')}>{t('rerankModel')}</FormLabel>
|
|
<FormControl>
|
|
<SelectWithSearch
|
|
allowClear
|
|
{...field}
|
|
options={options}
|
|
></SelectWithSearch>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export const rerankFormSchema = {
|
|
[RerankId]: z.string().optional(),
|
|
top_k: z.coerce.number().optional(),
|
|
};
|
|
|
|
export function RerankFormFields() {
|
|
const { watch } = useFormContext();
|
|
const { t } = useTranslate('knowledgeDetails');
|
|
const rerankId = watch(RerankId);
|
|
|
|
return (
|
|
<>
|
|
<RerankFormField></RerankFormField>
|
|
{rerankId && (
|
|
<SliderInputFormField
|
|
name={'top_k'}
|
|
label={t('topK')}
|
|
max={2048}
|
|
min={1}
|
|
tooltip={t('topKTip')}
|
|
></SliderInputFormField>
|
|
)}
|
|
</>
|
|
);
|
|
}
|