mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
Fix: Fixed the issue where clicking the SQL tool test button did not request the interface #9541 (#9542)
### What problem does this PR solve? Fix: Fixed the issue where clicking the SQL tool test button did not request the interface #9541 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
72
web/src/components/metadata-filter/index.tsx
Normal file
72
web/src/components/metadata-filter/index.tsx
Normal file
@ -0,0 +1,72 @@
|
||||
import { DatasetMetadata } from '@/constants/chat';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { useFormContext, useWatch } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
import { SelectWithSearch } from '../originui/select-with-search';
|
||||
import { RAGFlowFormItem } from '../ragflow-form';
|
||||
import { MetadataFilterConditions } from './metadata-filter-conditions';
|
||||
|
||||
type MetadataFilterProps = {
|
||||
prefix?: string;
|
||||
};
|
||||
|
||||
export const MetadataFilterSchema = {
|
||||
meta_data_filter: z
|
||||
.object({
|
||||
method: z.string().optional(),
|
||||
manual: z
|
||||
.array(
|
||||
z.object({
|
||||
key: z.string(),
|
||||
op: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
};
|
||||
|
||||
export function MetadataFilter({ prefix = '' }: MetadataFilterProps) {
|
||||
const { t } = useTranslate('chat');
|
||||
const form = useFormContext();
|
||||
|
||||
const methodName = prefix + 'meta_data_filter.method';
|
||||
|
||||
const kbIds: string[] = useWatch({
|
||||
control: form.control,
|
||||
name: prefix + 'kb_ids',
|
||||
});
|
||||
const metadata = useWatch({
|
||||
control: form.control,
|
||||
name: methodName,
|
||||
});
|
||||
const hasKnowledge = Array.isArray(kbIds) && kbIds.length > 0;
|
||||
|
||||
const MetadataOptions = Object.values(DatasetMetadata).map((x) => {
|
||||
return {
|
||||
value: x,
|
||||
label: t(`meta.${x}`),
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{hasKnowledge && (
|
||||
<RAGFlowFormItem
|
||||
label={t('metadata')}
|
||||
name={methodName}
|
||||
tooltip={t('metadataTip')}
|
||||
>
|
||||
<SelectWithSearch options={MetadataOptions} />
|
||||
</RAGFlowFormItem>
|
||||
)}
|
||||
{hasKnowledge && metadata === DatasetMetadata.Manual && (
|
||||
<MetadataFilterConditions
|
||||
kbIds={kbIds}
|
||||
prefix={prefix}
|
||||
></MetadataFilterConditions>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,135 @@
|
||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { useFetchKnowledgeMetadata } from '@/hooks/use-knowledge-request';
|
||||
import { SwitchOperatorOptions } from '@/pages/agent/constant';
|
||||
import { useBuildSwitchOperatorOptions } from '@/pages/agent/form/switch-form';
|
||||
import { Plus, X } from 'lucide-react';
|
||||
import { useCallback } from 'react';
|
||||
import { useFieldArray, useFormContext } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export function MetadataFilterConditions({
|
||||
kbIds,
|
||||
prefix = '',
|
||||
}: {
|
||||
kbIds: string[];
|
||||
prefix?: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const form = useFormContext();
|
||||
const name = prefix + 'meta_data_filter.manual';
|
||||
const metadata = useFetchKnowledgeMetadata(kbIds);
|
||||
|
||||
const switchOperatorOptions = useBuildSwitchOperatorOptions();
|
||||
|
||||
const { fields, remove, append } = useFieldArray({
|
||||
name,
|
||||
control: form.control,
|
||||
});
|
||||
|
||||
const add = useCallback(
|
||||
(key: string) => () => {
|
||||
append({
|
||||
key,
|
||||
value: '',
|
||||
op: SwitchOperatorOptions[0].value,
|
||||
});
|
||||
},
|
||||
[append],
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<FormLabel>{t('chat.conditions')}</FormLabel>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger>
|
||||
<Button variant={'ghost'} type="button">
|
||||
<Plus />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
{Object.keys(metadata.data).map((key, idx) => {
|
||||
return (
|
||||
<DropdownMenuItem key={idx} onClick={add(key)}>
|
||||
{key}
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
<div className="space-y-5">
|
||||
{fields.map((field, index) => {
|
||||
const typeField = `${name}.${index}.key`;
|
||||
return (
|
||||
<div key={field.id} className="flex w-full items-center gap-2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={typeField}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 overflow-hidden">
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder={t('common.pleaseInput')}
|
||||
></Input>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Separator className="w-3 text-text-secondary" />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`${name}.${index}.op`}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 overflow-hidden">
|
||||
<FormControl>
|
||||
<SelectWithSearch
|
||||
{...field}
|
||||
options={switchOperatorOptions}
|
||||
></SelectWithSearch>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Separator className="w-3 text-text-secondary" />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={`${name}.${index}.value`}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 overflow-hidden">
|
||||
<FormControl>
|
||||
<Input placeholder={t('common.pleaseInput')} {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Button variant={'ghost'} onClick={() => remove(index)}>
|
||||
<X className="text-text-sub-title-invert " />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@ -32,3 +32,9 @@ export enum ChatSearchParams {
|
||||
}
|
||||
|
||||
export const EmptyConversationId = 'empty';
|
||||
|
||||
export enum DatasetMetadata {
|
||||
Disabled = 'disabled',
|
||||
Automatic = 'automatic',
|
||||
Manual = 'manual',
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ export function Header() {
|
||||
const tagsData = useMemo(
|
||||
() => [
|
||||
{ path: Routes.Home, name: t('header.home'), icon: House },
|
||||
{ path: Routes.Datasets, name: t('header.knowledgeBase'), icon: Library },
|
||||
{ path: Routes.Datasets, name: t('header.dataset'), icon: Library },
|
||||
{ path: Routes.Chats, name: t('header.chat'), icon: MessageSquareText },
|
||||
{ path: Routes.Searches, name: t('header.search'), icon: Search },
|
||||
{ path: Routes.Agents, name: t('header.flow'), icon: Cpu },
|
||||
|
||||
@ -81,6 +81,7 @@ export default {
|
||||
flow: 'Agent',
|
||||
search: 'Search',
|
||||
welcome: 'Welcome to',
|
||||
dataset: 'Dataset',
|
||||
},
|
||||
knowledgeList: {
|
||||
welcome: 'Welcome back',
|
||||
|
||||
@ -73,6 +73,7 @@ export default {
|
||||
flow: 'Agent',
|
||||
search: '搜索',
|
||||
welcome: '欢迎来到',
|
||||
dataset: '数据集',
|
||||
},
|
||||
knowledgeList: {
|
||||
welcome: '欢迎回来',
|
||||
|
||||
@ -3,7 +3,6 @@ import { useCallback } from 'react';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ExeSQLFormSchema = {
|
||||
sql: z.string(),
|
||||
db_type: z.string().min(1),
|
||||
database: z.string().min(1),
|
||||
username: z.string().min(1),
|
||||
@ -14,7 +13,7 @@ export const ExeSQLFormSchema = {
|
||||
};
|
||||
|
||||
export const FormSchema = z.object({
|
||||
query: z.string().optional(),
|
||||
sql: z.string().optional(),
|
||||
...ExeSQLFormSchema,
|
||||
});
|
||||
|
||||
|
||||
@ -25,11 +25,13 @@ const ExeSQLForm = () => {
|
||||
defaultValues: defaultValues as FormType,
|
||||
});
|
||||
|
||||
const onError = (error: any) => console.log(error);
|
||||
|
||||
useWatchFormChange(form);
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<FormWrapper onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<FormWrapper onSubmit={form.handleSubmit(onSubmit, onError)}>
|
||||
<ExeSQLFormWidgets loading={loading}></ExeSQLFormWidgets>
|
||||
</FormWrapper>
|
||||
</Form>
|
||||
|
||||
@ -2,8 +2,7 @@
|
||||
|
||||
import { FileUploader } from '@/components/file-uploader';
|
||||
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||
import { RAGFlowFormItem } from '@/components/ragflow-form';
|
||||
import { MetadataFilter } from '@/components/metadata-filter';
|
||||
import { SwitchFormField } from '@/components/switch-fom-field';
|
||||
import { TavilyFormField } from '@/components/tavily-form-field';
|
||||
import {
|
||||
@ -16,26 +15,11 @@ import {
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { useFormContext, useWatch } from 'react-hook-form';
|
||||
import { DatasetMetadata } from '../../constants';
|
||||
import { MetadataFilterConditions } from './metadata-filter-conditions';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
|
||||
export default function ChatBasicSetting() {
|
||||
const { t } = useTranslate('chat');
|
||||
const form = useFormContext();
|
||||
const kbIds: string[] = useWatch({ control: form.control, name: 'kb_ids' });
|
||||
const metadata = useWatch({
|
||||
control: form.control,
|
||||
name: 'meta_data_filter.method',
|
||||
});
|
||||
const hasKnowledge = Array.isArray(kbIds) && kbIds.length > 0;
|
||||
|
||||
const MetadataOptions = Object.values(DatasetMetadata).map((x) => {
|
||||
return {
|
||||
value: x,
|
||||
label: t(`meta.${x}`),
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
@ -125,18 +109,7 @@ export default function ChatBasicSetting() {
|
||||
></SwitchFormField>
|
||||
<TavilyFormField></TavilyFormField>
|
||||
<KnowledgeBaseFormField></KnowledgeBaseFormField>
|
||||
{hasKnowledge && (
|
||||
<RAGFlowFormItem
|
||||
label={t('metadata')}
|
||||
name={'meta_data_filter.method'}
|
||||
tooltip={t('metadataTip')}
|
||||
>
|
||||
<SelectWithSearch options={MetadataOptions} />
|
||||
</RAGFlowFormItem>
|
||||
)}
|
||||
{hasKnowledge && metadata === DatasetMetadata.Manual && (
|
||||
<MetadataFilterConditions kbIds={kbIds}></MetadataFilterConditions>
|
||||
)}
|
||||
<MetadataFilter></MetadataFilter>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import {
|
||||
LlmSettingEnabledSchema,
|
||||
LlmSettingFieldSchema,
|
||||
} from '@/components/llm-setting-items/next';
|
||||
import { MetadataFilterSchema } from '@/components/metadata-filter';
|
||||
import { rerankFormSchema } from '@/components/rerank';
|
||||
import { vectorSimilarityWeightSchema } from '@/components/similarity-slider';
|
||||
import { topnSchema } from '@/components/top-n-item';
|
||||
@ -46,20 +47,7 @@ export function useChatSettingSchema() {
|
||||
llm_id: z.string().optional(),
|
||||
...vectorSimilarityWeightSchema,
|
||||
...topnSchema,
|
||||
meta_data_filter: z
|
||||
.object({
|
||||
method: z.string().optional(),
|
||||
manual: z
|
||||
.array(
|
||||
z.object({
|
||||
key: z.string(),
|
||||
op: z.string(),
|
||||
value: z.string(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
...MetadataFilterSchema,
|
||||
});
|
||||
|
||||
return formSchema;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { removeUselessFieldsFromValues } from '@/utils/form';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
|
||||
@ -23,7 +24,7 @@ export function useBuildFormRefs(chatBoxIds: string[]) {
|
||||
? formRefs.current[chatBoxId].getFormData()
|
||||
: {};
|
||||
|
||||
return llmConfig;
|
||||
return removeUselessFieldsFromValues(llmConfig, '');
|
||||
},
|
||||
[formRefs],
|
||||
);
|
||||
|
||||
@ -2,31 +2,8 @@ import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useSetDialog } from '@/hooks/use-chat-request';
|
||||
import { IDialog } from '@/interfaces/database/chat';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
const InitialData = {
|
||||
name: '',
|
||||
icon: '',
|
||||
language: 'English',
|
||||
prompt_config: {
|
||||
empty_response: '',
|
||||
prologue: '你好! 我是你的助理,有什么可以帮到你的吗?',
|
||||
quote: true,
|
||||
keyword: false,
|
||||
tts: false,
|
||||
system:
|
||||
'你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\n 以下是知识库:\n {knowledge}\n 以上是知识库。',
|
||||
refine_multiturn: false,
|
||||
use_kg: false,
|
||||
reasoning: false,
|
||||
parameters: [{ key: 'knowledge', optional: false }],
|
||||
},
|
||||
llm_id: '',
|
||||
llm_setting: {},
|
||||
similarity_threshold: 0.2,
|
||||
vector_similarity_weight: 0.30000000000000004,
|
||||
top_n: 8,
|
||||
};
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export const useRenameChat = () => {
|
||||
const [chat, setChat] = useState<IDialog>({} as IDialog);
|
||||
@ -36,6 +13,33 @@ export const useRenameChat = () => {
|
||||
showModal: showChatRenameModal,
|
||||
} = useSetModalState();
|
||||
const { setDialog, loading } = useSetDialog();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const InitialData = useMemo(
|
||||
() => ({
|
||||
name: '',
|
||||
icon: '',
|
||||
language: 'English',
|
||||
prompt_config: {
|
||||
empty_response: '',
|
||||
prologue: t('chat.setAnOpenerInitial'),
|
||||
quote: true,
|
||||
keyword: false,
|
||||
tts: false,
|
||||
system: t('chat.systemInitialValue'),
|
||||
refine_multiturn: false,
|
||||
use_kg: false,
|
||||
reasoning: false,
|
||||
parameters: [{ key: 'knowledge', optional: false }],
|
||||
},
|
||||
llm_id: '',
|
||||
llm_setting: {},
|
||||
similarity_threshold: 0.2,
|
||||
vector_similarity_weight: 0.30000000000000004,
|
||||
top_n: 8,
|
||||
}),
|
||||
[t],
|
||||
);
|
||||
|
||||
const onChatRenameOk = useCallback(
|
||||
async (name: string) => {
|
||||
@ -49,7 +53,7 @@ export const useRenameChat = () => {
|
||||
hideChatRenameModal();
|
||||
}
|
||||
},
|
||||
[setDialog, chat, hideChatRenameModal],
|
||||
[chat, InitialData, setDialog, hideChatRenameModal],
|
||||
);
|
||||
|
||||
const handleShowChatRenameModal = useCallback(
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
// src/pages/next-search/search-setting.tsx
|
||||
|
||||
import {
|
||||
MetadataFilter,
|
||||
MetadataFilterSchema,
|
||||
} from '@/components/metadata-filter';
|
||||
import { Input } from '@/components/originui/input';
|
||||
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@ -76,6 +80,7 @@ const SearchSettingFormSchema = z
|
||||
llm_setting: z.object(LlmSettingSchema),
|
||||
related_search: z.boolean(),
|
||||
query_mindmap: z.boolean(),
|
||||
...MetadataFilterSchema,
|
||||
}),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
@ -165,6 +170,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
keyword: false,
|
||||
related_search: search_config?.related_search || false,
|
||||
query_mindmap: search_config?.query_mindmap || false,
|
||||
meta_data_filter: search_config?.meta_data_filter,
|
||||
},
|
||||
});
|
||||
}, [data, search_config, llm_setting, formMethods]);
|
||||
@ -346,7 +352,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Avatar */}
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
@ -409,7 +414,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Description */}
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
@ -437,7 +441,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Datasets */}
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
@ -467,6 +470,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<MetadataFilter prefix="search_config."></MetadataFilter>
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
name="search_config.similarity_threshold"
|
||||
@ -541,7 +545,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Rerank Model */}
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
@ -617,7 +620,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* AI Summary */}
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
@ -634,14 +636,12 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{aiSummaryDisabled && (
|
||||
<LlmSettingFieldItems
|
||||
prefix="search_config.llm_setting"
|
||||
options={aiSummeryModelOptions}
|
||||
></LlmSettingFieldItems>
|
||||
)}
|
||||
|
||||
{/* Feature Controls */}
|
||||
{/* <FormField
|
||||
control={formMethods.control}
|
||||
@ -658,7 +658,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/> */}
|
||||
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
name="search_config.related_search"
|
||||
@ -674,7 +673,6 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={formMethods.control}
|
||||
name="search_config.query_mindmap"
|
||||
|
||||
@ -158,6 +158,10 @@ export interface ISearchAppDetailProps {
|
||||
vector_similarity_weight: number;
|
||||
web_search: boolean;
|
||||
chat_settingcross_languages: string[];
|
||||
meta_data_filter?: {
|
||||
method: string;
|
||||
manual: { key: string; op: string; value: string }[];
|
||||
};
|
||||
};
|
||||
tenant_id: string;
|
||||
update_time: number;
|
||||
|
||||
Reference in New Issue
Block a user