mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Fix #6600 Hello, I have the same business requirement as #6600. My use case is: We have many departments (> 20 now and increasing), and each department has its own knowledge base. Because the agent workflow is the same, so I want to change the knowledge base on the fly, instead of creating agents for every department. It now looks like this:  Knowledge bases can be selected from the dropdown, and passed through the variables in the table. All selected knowledge bases are used for retrieval. ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe):
112 lines
2.8 KiB
TypeScript
112 lines
2.8 KiB
TypeScript
import { DocumentParserType } from '@/constants/knowledge';
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
|
import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
|
import { UserOutlined } from '@ant-design/icons';
|
|
import { Avatar as AntAvatar, Form, Select, Space } from 'antd';
|
|
import { Book } from 'lucide-react';
|
|
import { useFormContext } from 'react-hook-form';
|
|
import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar';
|
|
import { FormControl, FormField, FormItem, FormLabel } from './ui/form';
|
|
import { MultiSelect } from './ui/multi-select';
|
|
|
|
interface KnowledgeBaseItemProps {
|
|
tooltipText?: string;
|
|
required?: boolean;
|
|
onChange?(): void;
|
|
}
|
|
|
|
const KnowledgeBaseItem = ({
|
|
tooltipText,
|
|
required = true,
|
|
onChange,
|
|
}: KnowledgeBaseItemProps) => {
|
|
const { t } = useTranslate('chat');
|
|
|
|
const { list: knowledgeList } = useFetchKnowledgeList(true);
|
|
|
|
const filteredKnowledgeList = knowledgeList.filter(
|
|
(x) => x.parser_id !== DocumentParserType.Tag,
|
|
);
|
|
|
|
const knowledgeOptions = filteredKnowledgeList.map((x) => ({
|
|
label: (
|
|
<Space>
|
|
<AntAvatar size={20} icon={<UserOutlined />} src={x.avatar} />
|
|
{x.name}
|
|
</Space>
|
|
),
|
|
value: x.id,
|
|
}));
|
|
|
|
return (
|
|
<Form.Item
|
|
label={t('knowledgeBases')}
|
|
name="kb_ids"
|
|
tooltip={tooltipText || t('knowledgeBasesTip')}
|
|
rules={[
|
|
{
|
|
required,
|
|
message: t('knowledgeBasesMessage'),
|
|
type: 'array',
|
|
},
|
|
]}
|
|
>
|
|
<Select
|
|
mode="multiple"
|
|
options={knowledgeOptions}
|
|
placeholder={t('knowledgeBasesMessage')}
|
|
onChange={onChange}
|
|
></Select>
|
|
</Form.Item>
|
|
);
|
|
};
|
|
|
|
export default KnowledgeBaseItem;
|
|
|
|
export function KnowledgeBaseFormField() {
|
|
const form = useFormContext();
|
|
const { t } = useTranslate('chat');
|
|
|
|
const { list: knowledgeList } = useFetchKnowledgeList(true);
|
|
|
|
const filteredKnowledgeList = knowledgeList.filter(
|
|
(x) => x.parser_id !== DocumentParserType.Tag,
|
|
);
|
|
|
|
const knowledgeOptions = filteredKnowledgeList.map((x) => ({
|
|
label: x.name,
|
|
value: x.id,
|
|
icon: () => (
|
|
<Avatar className="size-4 mr-2">
|
|
<AvatarImage src={x.avatar} />
|
|
<AvatarFallback>
|
|
<Book />
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
),
|
|
}));
|
|
|
|
return (
|
|
<FormField
|
|
control={form.control}
|
|
name="kb_ids"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('knowledgeBases')}</FormLabel>
|
|
<FormControl>
|
|
<MultiSelect
|
|
options={knowledgeOptions}
|
|
onValueChange={field.onChange}
|
|
placeholder={t('knowledgeBasesMessage')}
|
|
variant="inverted"
|
|
maxCount={100}
|
|
defaultValue={field.value}
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
);
|
|
}
|