Files
ragflow/web/src/components/rerank.tsx
chanx 8b534c895e Fix: UI Placeholder and Hint Optimization (#13416)
### What problem does this PR solve?

Fix: UI Placeholder and Hint Optimization

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
2026-03-05 18:13:19 +08:00

79 lines
1.9 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
placeholder={t('rerankPlaceholder')}
{...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>
)}
</>
);
}