2024-05-29 16:19:08 +08:00
|
|
|
import { LlmModelType } from '@/constants/knowledge';
|
2024-07-17 19:07:34 +08:00
|
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
2025-12-02 17:24:29 +08:00
|
|
|
import { useSelectLlmOptionsByModelType } from '@/hooks/use-llm-request';
|
2025-02-11 19:04:10 +08:00
|
|
|
import { useFormContext } from 'react-hook-form';
|
2025-05-16 18:56:48 +08:00
|
|
|
import { z } from 'zod';
|
2025-08-13 10:26:26 +08:00
|
|
|
import { SelectWithSearch } from './originui/select-with-search';
|
2025-05-16 18:56:48 +08:00
|
|
|
import { SliderInputFormField } from './slider-input-form-field';
|
2025-02-11 19:04:10 +08:00
|
|
|
import {
|
|
|
|
|
FormControl,
|
|
|
|
|
FormField,
|
|
|
|
|
FormItem,
|
|
|
|
|
FormLabel,
|
|
|
|
|
FormMessage,
|
|
|
|
|
} from './ui/form';
|
2024-05-29 16:19:08 +08:00
|
|
|
|
2025-05-16 18:56:48 +08:00
|
|
|
export const topKSchema = {
|
|
|
|
|
top_k: z.number().optional(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const initialTopKValue = {
|
|
|
|
|
top_k: 1024,
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-11 19:04:10 +08:00
|
|
|
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>
|
2025-04-17 19:03:55 +08:00
|
|
|
<FormLabel tooltip={t('rerankTip')}>{t('rerankModel')}</FormLabel>
|
2025-02-11 19:04:10 +08:00
|
|
|
<FormControl>
|
2025-08-13 10:26:26 +08:00
|
|
|
<SelectWithSearch
|
2025-06-03 15:40:04 +08:00
|
|
|
allowClear
|
|
|
|
|
{...field}
|
|
|
|
|
options={options}
|
2025-08-13 10:26:26 +08:00
|
|
|
></SelectWithSearch>
|
2025-02-11 19:04:10 +08:00
|
|
|
</FormControl>
|
|
|
|
|
<FormMessage />
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 10:26:26 +08:00
|
|
|
export const rerankFormSchema = {
|
|
|
|
|
[RerankId]: z.string().optional(),
|
|
|
|
|
top_k: z.coerce.number().optional(),
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-11 19:04:10 +08:00
|
|
|
export function RerankFormFields() {
|
2025-05-16 18:56:48 +08:00
|
|
|
const { watch } = useFormContext();
|
2025-02-11 19:04:10 +08:00
|
|
|
const { t } = useTranslate('knowledgeDetails');
|
|
|
|
|
const rerankId = watch(RerankId);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<RerankFormField></RerankFormField>
|
|
|
|
|
{rerankId && (
|
2025-05-16 18:56:48 +08:00
|
|
|
<SliderInputFormField
|
2025-02-11 19:04:10 +08:00
|
|
|
name={'top_k'}
|
2025-05-16 18:56:48 +08:00
|
|
|
label={t('topK')}
|
|
|
|
|
max={2048}
|
|
|
|
|
min={1}
|
|
|
|
|
tooltip={t('topKTip')}
|
|
|
|
|
></SliderInputFormField>
|
2025-02-11 19:04:10 +08:00
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|