mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
169 lines
4.8 KiB
TypeScript
169 lines
4.8 KiB
TypeScript
import KnowledgeBaseItem from '@/components/knowledge-base-item';
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
|
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
import { Form, Input, message, Select, Switch, Typography, Upload } from 'antd';
|
|
import classNames from 'classnames';
|
|
import { useCallback } from 'react';
|
|
import { ISegmentedContentProps } from '../interface';
|
|
|
|
import styles from './index.less';
|
|
|
|
const emptyResponseField = ['prompt_config', 'empty_response'];
|
|
|
|
const AssistantSetting = ({
|
|
show,
|
|
form,
|
|
setHasError,
|
|
}: ISegmentedContentProps) => {
|
|
const { t } = useTranslate('chat');
|
|
const { data } = useFetchTenantInfo(true);
|
|
|
|
const handleChange = useCallback(() => {
|
|
const kbIds = form.getFieldValue('kb_ids');
|
|
const emptyResponse = form.getFieldValue(emptyResponseField);
|
|
|
|
const required =
|
|
emptyResponse && ((Array.isArray(kbIds) && kbIds.length === 0) || !kbIds);
|
|
|
|
setHasError(required);
|
|
form.setFields([
|
|
{
|
|
name: emptyResponseField,
|
|
errors: required ? [t('emptyResponseMessage')] : [],
|
|
},
|
|
]);
|
|
}, [form, setHasError, t]);
|
|
|
|
const normFile = (e: any) => {
|
|
if (Array.isArray(e)) {
|
|
return e;
|
|
}
|
|
return e?.fileList;
|
|
};
|
|
|
|
const handleTtsChange = useCallback(
|
|
(checked: boolean) => {
|
|
if (checked && !data.tts_id) {
|
|
message.error(`Please set TTS model firstly.
|
|
Setting >> Model providers >> System model settings`);
|
|
form.setFieldValue(['prompt_config', 'tts'], false);
|
|
}
|
|
},
|
|
[data, form],
|
|
);
|
|
|
|
const uploadButton = (
|
|
<button style={{ border: 0, background: 'none' }} type="button">
|
|
<PlusOutlined />
|
|
<div style={{ marginTop: 8 }}>{t('upload', { keyPrefix: 'common' })}</div>
|
|
</button>
|
|
);
|
|
|
|
return (
|
|
<section
|
|
className={classNames({
|
|
[styles.segmentedHidden]: !show,
|
|
})}
|
|
>
|
|
<Form.Item
|
|
name={'name'}
|
|
label={t('assistantName')}
|
|
rules={[{ required: true, message: t('assistantNameMessage') }]}
|
|
>
|
|
<Input placeholder={t('namePlaceholder')} />
|
|
</Form.Item>
|
|
<Form.Item name={'description'} label={t('description')}>
|
|
<Input placeholder={t('descriptionPlaceholder')} />
|
|
</Form.Item>
|
|
<Form.Item
|
|
name="icon"
|
|
label={t('assistantAvatar')}
|
|
valuePropName="fileList"
|
|
getValueFromEvent={normFile}
|
|
>
|
|
<Upload
|
|
listType="picture-card"
|
|
maxCount={1}
|
|
beforeUpload={() => false}
|
|
showUploadList={{ showPreviewIcon: false, showRemoveIcon: false }}
|
|
>
|
|
{show ? uploadButton : null}
|
|
</Upload>
|
|
</Form.Item>
|
|
<Form.Item
|
|
name={'language'}
|
|
label={t('language')}
|
|
initialValue={'English'}
|
|
tooltip="coming soon"
|
|
style={{ display: 'none' }}
|
|
>
|
|
<Select
|
|
options={[
|
|
{ value: 'Chinese', label: t('chinese', { keyPrefix: 'common' }) },
|
|
{ value: 'English', label: t('english', { keyPrefix: 'common' }) },
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item
|
|
name={emptyResponseField}
|
|
label={t('emptyResponse')}
|
|
tooltip={t('emptyResponseTip')}
|
|
>
|
|
<Input placeholder="" onChange={handleChange} />
|
|
</Form.Item>
|
|
<Form.Item
|
|
name={['prompt_config', 'prologue']}
|
|
label={t('setAnOpener')}
|
|
tooltip={t('setAnOpenerTip')}
|
|
initialValue={t('setAnOpenerInitial')}
|
|
>
|
|
<Input.TextArea autoSize={{ minRows: 5 }} />
|
|
</Form.Item>
|
|
<Form.Item
|
|
label={t('quote')}
|
|
valuePropName="checked"
|
|
name={['prompt_config', 'quote']}
|
|
tooltip={t('quoteTip')}
|
|
initialValue={true}
|
|
>
|
|
<Switch />
|
|
</Form.Item>
|
|
<Form.Item
|
|
label={t('keyword')}
|
|
valuePropName="checked"
|
|
name={['prompt_config', 'keyword']}
|
|
tooltip={t('keywordTip')}
|
|
initialValue={false}
|
|
>
|
|
<Switch />
|
|
</Form.Item>
|
|
<Form.Item
|
|
label={t('tts')}
|
|
valuePropName="checked"
|
|
name={['prompt_config', 'tts']}
|
|
tooltip={t('ttsTip')}
|
|
initialValue={false}
|
|
>
|
|
<Switch onChange={handleTtsChange} />
|
|
</Form.Item>
|
|
<Form.Item label={'Tavily API Key'} tooltip={t('tavilyApiKeyTip')}>
|
|
<div className="flex flex-col gap-1">
|
|
<Form.Item name={['prompt_config', 'tavily_api_key']} noStyle>
|
|
<Input.Password placeholder={t('tavilyApiKeyMessage')} />
|
|
</Form.Item>
|
|
<Typography.Link href="https://app.tavily.com/home" target={'_blank'}>
|
|
{t('tavilyApiKeyHelp')}
|
|
</Typography.Link>
|
|
</div>
|
|
</Form.Item>
|
|
<KnowledgeBaseItem
|
|
required={false}
|
|
onChange={handleChange}
|
|
></KnowledgeBaseItem>
|
|
</section>
|
|
);
|
|
};
|
|
|
|
export default AssistantSetting;
|