File size: 5,114 Bytes
f28c040
2faf924
6aa5abc
0cf2c67
980e3c4
 
 
68ed806
7b030d6
2faf924
 
 
967c830
2faf924
 
 
 
f3d0ebd
 
 
 
967c830
badd5fe
 
60101af
967c830
badd5fe
7b030d6
f3d0ebd
 
badd5fe
 
967c830
 
 
 
badd5fe
967c830
 
 
 
 
 
 
 
f3d0ebd
967c830
 
badd5fe
967c830
 
 
badd5fe
967c830
 
 
badd5fe
967c830
cfbf213
badd5fe
967c830
badd5fe
 
 
967c830
 
 
 
88e5a61
badd5fe
967c830
 
 
badd5fe
 
967c830
 
 
 
88e5a61
967c830
badd5fe
967c830
 
badd5fe
967c830
60101af
967c830
 
 
 
88e5a61
badd5fe
967c830
 
7b030d6
 
 
 
 
967c830
 
 
 
 
 
 
e2220ea
967c830
 
 
f30b544
980e3c4
 
e2220ea
7b030d6
 
 
 
 
e2220ea
980e3c4
 
 
f28c040
980e3c4
 
 
 
 
 
 
 
967c830
 
6aa5abc
967c830
 
 
badd5fe
 
967c830
 
 
 
 
badd5fe
967c830
badd5fe
967c830
 
 
 
 
f3d0ebd
 
 
967c830
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import Delimiter from '@/components/delimiter';
import EntityTypesItem from '@/components/entity-types-item';
import LayoutRecognize from '@/components/layout-recognize';
import MaxTokenNumber from '@/components/max-token-number';
import ParseConfiguration, {
  showRaptorParseConfiguration,
} from '@/components/parse-configuration';
import { useTranslate } from '@/hooks/common-hooks';
import { useHandleChunkMethodSelectChange } from '@/hooks/logic-hooks';
import { normFile } from '@/utils/file-util';
import { PlusOutlined } from '@ant-design/icons';
import { Button, Form, Input, Radio, Select, Space, Upload } from 'antd';
import { FormInstance } from 'antd/lib';
import {
  useFetchKnowledgeConfigurationOnMount,
  useSubmitKnowledgeConfiguration,
} from './hooks';
import styles from './index.less';

const { Option } = Select;

const ConfigurationForm = ({ form }: { form: FormInstance }) => {
  const { submitKnowledgeConfiguration, submitLoading, navigateToDataset } =
    useSubmitKnowledgeConfiguration(form);
  const { parserList, embeddingModelOptions, disabled } =
    useFetchKnowledgeConfigurationOnMount(form);
  const { t } = useTranslate('knowledgeConfiguration');
  const handleChunkMethodSelectChange = useHandleChunkMethodSelectChange(form);

  return (
    <Form form={form} name="validateOnly" layout="vertical" autoComplete="off">
      <Form.Item name="name" label={t('name')} rules={[{ required: true }]}>
        <Input />
      </Form.Item>
      <Form.Item
        name="avatar"
        label={t('photo')}
        valuePropName="fileList"
        getValueFromEvent={normFile}
      >
        <Upload
          listType="picture-card"
          maxCount={1}
          beforeUpload={() => false}
          showUploadList={{ showPreviewIcon: false, showRemoveIcon: false }}
        >
          <button style={{ border: 0, background: 'none' }} type="button">
            <PlusOutlined />
            <div style={{ marginTop: 8 }}>{t('upload')}</div>
          </button>
        </Upload>
      </Form.Item>
      <Form.Item name="description" label={t('description')}>
        <Input />
      </Form.Item>
      <Form.Item
        label={t('language')}
        name="language"
        initialValue={'English'}
        rules={[{ required: true, message: t('languageMessage') }]}
      >
        <Select placeholder={t('languagePlaceholder')}>
          <Option value="English">{t('english')}</Option>
          <Option value="Chinese">{t('chinese')}</Option>
        </Select>
      </Form.Item>
      <Form.Item
        name="permission"
        label={t('permissions')}
        tooltip={t('permissionsTip')}
        rules={[{ required: true }]}
      >
        <Radio.Group>
          <Radio value="me">{t('me')}</Radio>
          <Radio value="team">{t('team')}</Radio>
        </Radio.Group>
      </Form.Item>
      <Form.Item
        name="embd_id"
        label={t('embeddingModel')}
        rules={[{ required: true }]}
        tooltip={t('embeddingModelTip')}
      >
        <Select
          placeholder={t('embeddingModelPlaceholder')}
          options={embeddingModelOptions}
          disabled={disabled}
        ></Select>
      </Form.Item>
      <Form.Item
        name="parser_id"
        label={t('chunkMethod')}
        tooltip={t('chunkMethodTip')}
        rules={[{ required: true }]}
      >
        <Select
          placeholder={t('chunkMethodPlaceholder')}
          disabled={disabled}
          onChange={handleChunkMethodSelectChange}
        >
          {parserList.map((x) => (
            <Option value={x.value} key={x.value}>
              {x.label}
            </Option>
          ))}
        </Select>
      </Form.Item>

      <Form.Item noStyle dependencies={['parser_id']}>
        {({ getFieldValue }) => {
          const parserId = getFieldValue('parser_id');

          return (
            <>
              {parserId === 'knowledge_graph' && (
                <>
                  <EntityTypesItem></EntityTypesItem>
                  <MaxTokenNumber max={8192 * 2}></MaxTokenNumber>
                  <Delimiter></Delimiter>
                </>
              )}
              {parserId === 'naive' && (
                <>
                  <MaxTokenNumber></MaxTokenNumber>
                  <Delimiter></Delimiter>
                  <LayoutRecognize></LayoutRecognize>
                </>
              )}
              {showRaptorParseConfiguration(parserId) && (
                <ParseConfiguration></ParseConfiguration>
              )}
            </>
          );
        }}
      </Form.Item>

      <Form.Item>
        <div className={styles.buttonWrapper}>
          <Space>
            <Button size={'middle'} onClick={navigateToDataset}>
              {t('cancel')}
            </Button>
            <Button
              type="primary"
              size={'middle'}
              loading={submitLoading}
              onClick={submitKnowledgeConfiguration}
            >
              {t('save')}
            </Button>
          </Space>
        </div>
      </Form.Item>
    </Form>
  );
};

export default ConfigurationForm;