2024-03-20 11:13:51 +08:00
import { normFile } from '@/utils/fileUtil' ;
2024-03-12 18:58:09 +08:00
import { PlusOutlined } from '@ant-design/icons' ;
2024-03-22 16:57:09 +08:00
import { Button , Form , Input , Radio , Select , Space , Upload } from 'antd' ;
2024-03-20 11:13:51 +08:00
import {
useFetchKnowledgeConfigurationOnMount ,
useSubmitKnowledgeConfiguration ,
} from './hooks' ;
2024-03-12 18:58:09 +08:00
2024-03-22 16:57:09 +08:00
import MaxTokenNumber from '@/components/max-token-number' ;
2024-03-21 16:45:03 +08:00
import { FormInstance } from 'antd/lib' ;
2024-02-18 18:18:20 +08:00
import styles from './index.less' ;
const { Option } = Select ;
2024-03-21 16:45:03 +08:00
const ConfigurationForm = ( { form } : { form : FormInstance } ) = > {
2024-03-20 11:13:51 +08:00
const { submitKnowledgeConfiguration , submitLoading } =
useSubmitKnowledgeConfiguration ( ) ;
2024-03-28 11:42:40 +08:00
const { parserList , embeddingModelOptions , disabled } =
2024-03-21 16:45:03 +08:00
useFetchKnowledgeConfigurationOnMount ( form ) ;
2024-02-18 18:18:20 +08:00
const onFinishFailed = ( errorInfo : any ) = > {
console . log ( 'Failed:' , errorInfo ) ;
} ;
return (
2024-03-21 16:45:03 +08:00
< Form
form = { form }
name = "validateOnly"
layout = "vertical"
autoComplete = "off"
onFinish = { submitKnowledgeConfiguration }
onFinishFailed = { onFinishFailed }
>
< Form.Item
name = "name"
label = "Knowledge base name"
rules = { [ { required : true } ] }
>
< Input / >
< / Form.Item >
< Form.Item
name = "avatar"
label = "Knowledge base photo"
valuePropName = "fileList"
getValueFromEvent = { normFile }
>
< Upload
listType = "picture-card"
maxCount = { 1 }
beforeUpload = { ( ) = > false }
showUploadList = { { showPreviewIcon : false , showRemoveIcon : false } }
2024-02-18 18:18:20 +08:00
>
2024-03-21 16:45:03 +08:00
< button style = { { border : 0 , background : 'none' } } type = "button" >
< PlusOutlined / >
< div style = { { marginTop : 8 } } > Upload < / div >
< / button >
< / Upload >
< / Form.Item >
< Form.Item name = "description" label = "Description" >
< Input / >
< / Form.Item >
< Form.Item
label = "Language"
name = "language"
2024-04-01 10:54:11 +08:00
initialValue = { 'English' }
2024-03-21 16:45:03 +08:00
rules = { [ { required : true , message : 'Please input your language!' } ] }
>
< Select placeholder = "select your language" >
< Option value = "English" > English < / Option >
< Option value = "Chinese" > Chinese < / Option >
< / Select >
< / Form.Item >
< Form.Item
name = "permission"
label = "Permissions"
2024-03-22 15:35:06 +08:00
tooltip = "If the permission is 'Team', all the team member can manipulate the knowledgebase."
2024-03-21 16:45:03 +08:00
rules = { [ { required : true } ] }
>
< Radio.Group >
< Radio value = "me" > Only me < / Radio >
< Radio value = "team" > Team < / Radio >
< / Radio.Group >
< / Form.Item >
< Form.Item
name = "embd_id"
2024-03-22 15:35:06 +08:00
label = "Embedding model"
2024-03-21 16:45:03 +08:00
rules = { [ { required : true } ] }
2024-03-22 15:35:06 +08:00
tooltip = "The embedding model used to embedding chunks. It's unchangable once the knowledgebase has chunks. You need to delete all the chunks if you want to change it."
2024-03-21 16:45:03 +08:00
>
< Select
2024-03-22 15:35:06 +08:00
placeholder = "Please select a embedding model"
2024-03-21 16:45:03 +08:00
options = { embeddingModelOptions }
2024-03-28 11:42:40 +08:00
disabled = { disabled }
2024-03-21 16:45:03 +08:00
> < / Select >
< / Form.Item >
< Form.Item
name = "parser_id"
label = "Chunk method"
2024-03-22 15:35:06 +08:00
tooltip = "The instruction is at right."
2024-03-21 16:45:03 +08:00
rules = { [ { required : true } ] }
>
2024-03-28 11:42:40 +08:00
< Select placeholder = "Please select a chunk method" disabled = { disabled } >
2024-03-21 16:45:03 +08:00
{ 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' ) ;
2024-03-11 16:13:34 +08:00
2024-03-21 16:45:03 +08:00
if ( parserId === 'naive' ) {
2024-03-22 16:57:09 +08:00
return < MaxTokenNumber > < / MaxTokenNumber > ;
2024-03-21 16:45:03 +08:00
}
return null ;
} }
< / Form.Item >
< Form.Item >
< div className = { styles . buttonWrapper } >
< Space >
< Button htmlType = "reset" size = { 'middle' } >
Cancel
< / Button >
< Button
htmlType = "submit"
type = "primary"
size = { 'middle' }
loading = { submitLoading }
>
Save
< / Button >
< / Space >
< / div >
< / Form.Item >
< / Form >
2024-02-18 18:18:20 +08:00
) ;
} ;
2024-03-21 16:45:03 +08:00
export default ConfigurationForm ;