mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-30 23:26:36 +08:00
Fix:Bugs fix (Reduce metadata saving steps ...) (#12095)
### What problem does this PR solve? Fix:Bugs fix - Configure memory and metadata (in Chinese) - Add indexing modal - Reduce metadata saving steps ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import message from '@/components/ui/message';
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useSetDocumentMeta } from '@/hooks/use-document-request';
|
||||
import {
|
||||
import kbService, {
|
||||
getMetaDataService,
|
||||
updateMetaData,
|
||||
} from '@/services/knowledge-service';
|
||||
@ -255,7 +255,7 @@ export const useManageMetaDataModal = (
|
||||
data: operations,
|
||||
});
|
||||
if (res.code === 0) {
|
||||
message.success(t('message.success'));
|
||||
message.success(t('message.operated'));
|
||||
callback();
|
||||
}
|
||||
},
|
||||
@ -282,11 +282,18 @@ export const useManageMetaDataModal = (
|
||||
const handleSaveSettings = useCallback(
|
||||
async (callback: () => void) => {
|
||||
const data = util.tableDataToMetaDataSettingJSON(tableData);
|
||||
callback();
|
||||
const { data: res } = await kbService.kbUpdateMetaData({
|
||||
kb_id: id,
|
||||
metadata: data,
|
||||
});
|
||||
if (res.code === 0) {
|
||||
message.success(t('message.operated'));
|
||||
callback?.();
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
[tableData],
|
||||
[tableData, id],
|
||||
);
|
||||
|
||||
const handleSave = useCallback(
|
||||
|
||||
@ -27,7 +27,7 @@ import {
|
||||
import { Plus, Settings, Trash2 } from 'lucide-react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useManageMetaDataModal } from './hook';
|
||||
import { MetadataType, useManageMetaDataModal } from './hook';
|
||||
import { IManageModalProps, IMetaDataTableData } from './interface';
|
||||
import { ManageValuesModal } from './manage-values-modal';
|
||||
export const ManageMetadataModal = (props: IManageModalProps) => {
|
||||
@ -335,7 +335,13 @@ export const ManageMetadataModal = (props: IManageModalProps) => {
|
||||
</Modal>
|
||||
{manageValuesVisible && (
|
||||
<ManageValuesModal
|
||||
title={<div>{t('knowledgeDetails.metadata.editMetadata')}</div>}
|
||||
title={
|
||||
<div>
|
||||
{metadataType === MetadataType.Setting
|
||||
? t('knowledgeDetails.metadata.fieldSetting')
|
||||
: t('knowledgeDetails.metadata.editMetadata')}
|
||||
</div>
|
||||
}
|
||||
visible={manageValuesVisible}
|
||||
hideModal={hideManageValuesModal}
|
||||
data={valueData}
|
||||
|
||||
@ -154,7 +154,7 @@ export const ManageValuesModal = (props: IManageValuesProps) => {
|
||||
open={visible}
|
||||
onCancel={handleHideModal}
|
||||
className="!w-[460px]"
|
||||
okText={t('common.save')}
|
||||
okText={t('common.confirm')}
|
||||
onOk={handleSave}
|
||||
maskClosable={false}
|
||||
footer={null}
|
||||
|
||||
@ -3,7 +3,10 @@ import {
|
||||
FormFieldType,
|
||||
RenderField,
|
||||
} from '@/components/dynamic-form';
|
||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||
import {
|
||||
SelectWithSearch,
|
||||
SelectWithSearchFlagOptionType,
|
||||
} from '@/components/originui/select-with-search';
|
||||
import { SliderInputFormField } from '@/components/slider-input-form-field';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
@ -16,7 +19,9 @@ import {
|
||||
import { Radio } from '@/components/ui/radio';
|
||||
import { Spin } from '@/components/ui/spin';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { LlmModelType } from '@/constants/knowledge';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { useComposeLlmOptionsByModelTypes } from '@/hooks/use-llm-request';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { t } from 'i18next';
|
||||
import { Settings } from 'lucide-react';
|
||||
@ -41,6 +46,8 @@ import {
|
||||
interface IProps {
|
||||
line?: 1 | 2;
|
||||
isEdit?: boolean;
|
||||
label?: string;
|
||||
name?: string;
|
||||
}
|
||||
export function ChunkMethodItem(props: IProps) {
|
||||
const { line } = props;
|
||||
@ -368,7 +375,7 @@ export function AutoMetadata() {
|
||||
type: FormFieldType.Custom,
|
||||
horizontal: true,
|
||||
defaultValue: true,
|
||||
|
||||
tooltip: t('knowledgeConfiguration.autoMetadataTip'),
|
||||
render: (fieldProps: ControllerRenderProps) => (
|
||||
<div className="flex items-center justify-between">
|
||||
<Button
|
||||
@ -432,3 +439,80 @@ export function AutoMetadata() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const LLMSelect = ({
|
||||
isEdit,
|
||||
field,
|
||||
disabled = false,
|
||||
}: {
|
||||
isEdit: boolean;
|
||||
field: FieldValues;
|
||||
name?: string;
|
||||
disabled?: boolean;
|
||||
}) => {
|
||||
const { t } = useTranslate('knowledgeConfiguration');
|
||||
const modelOptions = useComposeLlmOptionsByModelTypes([
|
||||
LlmModelType.Chat,
|
||||
LlmModelType.Image2text,
|
||||
]);
|
||||
return (
|
||||
<SelectWithSearch
|
||||
onChange={async (value) => {
|
||||
field.onChange(value);
|
||||
}}
|
||||
disabled={disabled && !isEdit}
|
||||
value={field.value}
|
||||
options={modelOptions as SelectWithSearchFlagOptionType[]}
|
||||
placeholder={t('embeddingModelPlaceholder')}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export function LLMModelItem({ line = 1, isEdit, label, name }: IProps) {
|
||||
const { t } = useTranslate('knowledgeConfiguration');
|
||||
const form = useFormContext();
|
||||
const disabled = useHasParsedDocument(isEdit);
|
||||
return (
|
||||
<>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={name ?? 'llm_id'}
|
||||
render={({ field }) => (
|
||||
<FormItem className={cn(' items-center space-y-0 ')}>
|
||||
<div
|
||||
className={cn('flex', {
|
||||
' items-center': line === 1,
|
||||
'flex-col gap-1': line === 2,
|
||||
})}
|
||||
>
|
||||
<FormLabel
|
||||
required
|
||||
tooltip={t('globalIndexModelTip')}
|
||||
className={cn('text-sm whitespace-wrap ', {
|
||||
'w-1/4': line === 1,
|
||||
})}
|
||||
>
|
||||
{label ?? t('llmModel')}
|
||||
</FormLabel>
|
||||
<div
|
||||
className={cn('text-text-secondary', { 'w-3/4': line === 1 })}
|
||||
>
|
||||
<FormControl>
|
||||
<LLMSelect
|
||||
isEdit={!!isEdit}
|
||||
field={field}
|
||||
disabled={disabled}
|
||||
></LLMSelect>
|
||||
</FormControl>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex pt-1">
|
||||
<div className={line === 1 ? 'w-1/4' : ''}></div>
|
||||
<FormMessage />
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -96,6 +96,7 @@ export const formSchema = z
|
||||
)
|
||||
.optional(),
|
||||
enable_metadata: z.boolean().optional(),
|
||||
llm_id: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
pagerank: z.number(),
|
||||
|
||||
@ -93,6 +93,7 @@ export default function DatasetSettings() {
|
||||
},
|
||||
metadata: [],
|
||||
enable_metadata: false,
|
||||
llm_id: '',
|
||||
},
|
||||
pipeline_id: '',
|
||||
parseType: 1,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { DynamicForm } from '@/components/dynamic-form';
|
||||
import { useModelOptions } from '@/components/llm-setting-items/llm-form-field';
|
||||
import { HomeIcon } from '@/components/svg-icon';
|
||||
import { Modal } from '@/components/ui/modal/modal';
|
||||
import { memo, useMemo } from 'react';
|
||||
@ -18,7 +17,7 @@ type IProps = {
|
||||
export const AddOrEditModal = memo((props: IProps) => {
|
||||
const { open, onClose, onSubmit, initialMemory, isCreate } = props;
|
||||
const { t } = useTranslation();
|
||||
const { modelOptions } = useModelOptions();
|
||||
// const { modelOptions } = useModelOptions();
|
||||
|
||||
const fields = useMemo(() => {
|
||||
if (!isCreate) {
|
||||
@ -26,21 +25,22 @@ export const AddOrEditModal = memo((props: IProps) => {
|
||||
(field: any) => field.name === 'name',
|
||||
);
|
||||
} else {
|
||||
const tempFields = createMemoryFields(t).map((field: any) => {
|
||||
if (field.name === 'llm_id') {
|
||||
return {
|
||||
...field,
|
||||
options: modelOptions,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...field,
|
||||
};
|
||||
}
|
||||
});
|
||||
return tempFields;
|
||||
// const tempFields = createMemoryFields(t).map((field: any) => {
|
||||
// if (field.name === 'llm_id') {
|
||||
// return {
|
||||
// ...field,
|
||||
// options: modelOptions,
|
||||
// };
|
||||
// } else {
|
||||
// return {
|
||||
// ...field,
|
||||
// };
|
||||
// }
|
||||
// });
|
||||
// return tempFields;
|
||||
return createMemoryFields(t);
|
||||
}
|
||||
}, [modelOptions, isCreate]);
|
||||
}, [isCreate, t]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { FormFieldConfig, FormFieldType } from '@/components/dynamic-form';
|
||||
import { EmbeddingSelect } from '@/pages/dataset/dataset-setting/configuration/common-item';
|
||||
import {
|
||||
EmbeddingSelect,
|
||||
LLMSelect,
|
||||
} from '@/pages/dataset/dataset-setting/configuration/common-item';
|
||||
import { TFunction } from 'i18next';
|
||||
export enum MemoryType {
|
||||
Raw = 'raw',
|
||||
@ -52,6 +55,7 @@ export const createMemoryFields = (t: TFunction) =>
|
||||
required: true,
|
||||
type: FormFieldType.Select,
|
||||
tooltip: t('memories.llmTooltip'),
|
||||
render: (field) => <LLMSelect field={field} isEdit={false} />,
|
||||
},
|
||||
] as FormFieldConfig[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user