Merge remote-tracking branch 'origin/new-page-framework' into llm_framework

This commit is contained in:
aries_ckt 2023-06-30 16:36:27 +08:00
commit 0a382b64db
3 changed files with 553 additions and 335 deletions

View File

@ -1,13 +1,21 @@
'use client' 'use client'
import { useSearchParams } from 'next/navigation' import { useSearchParams, useRouter } from 'next/navigation'
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { useColorScheme, Table, Stack } from '@/lib/mui' import {
useColorScheme,
Table,
Stack,
Typography,
Breadcrumbs,
Link
} from '@/lib/mui'
import { Popover, Pagination } from 'antd' import { Popover, Pagination } from 'antd'
import { fetchBaseURL } from '@/app/datastores/constants' import { fetchBaseURL } from '@/app/datastores/constants'
const page_size = 20 const page_size = 20
const ChunkList = () => { const ChunkList = () => {
const router = useRouter()
const { mode } = useColorScheme() const { mode } = useColorScheme()
const spaceName = useSearchParams().get('spacename') const spaceName = useSearchParams().get('spacename')
const documentId = useSearchParams().get('documentid') const documentId = useSearchParams().get('documentid')
@ -40,6 +48,39 @@ const ChunkList = () => {
fetchChunks() fetchChunks()
}, []) }, [])
return ( return (
<div className="p-4">
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
sx={{ marginBottom: '20px' }}
>
<Breadcrumbs aria-label="breadcrumbs">
<Link
onClick={() => {
router.push('/datastores')
}}
key="Knowledge Space"
underline="hover"
color="neutral"
fontSize="inherit"
>
Knowledge Space
</Link>
<Link
onClick={() => {
router.push(`/datastores/documents?name=${spaceName}`)
}}
key="Knowledge Space"
underline="hover"
color="neutral"
fontSize="inherit"
>
Documents
</Link>
<Typography fontSize="inherit">Chunks</Typography>
</Breadcrumbs>
</Stack>
<div className="p-4"> <div className="p-4">
{chunkList.length ? ( {chunkList.length ? (
<> <>
@ -80,7 +121,11 @@ const ChunkList = () => {
<td> <td>
{ {
<Popover <Popover
content={JSON.stringify(row.meta_info || '{}', null, 2)} content={JSON.stringify(
row.meta_info || '{}',
null,
2
)}
trigger="hover" trigger="hover"
> >
{row.meta_info.length > 10 {row.meta_info.length > 10
@ -135,6 +180,7 @@ const ChunkList = () => {
<></> <></>
)} )}
</div> </div>
</div>
) )
} }

View File

@ -13,10 +13,15 @@ import {
Input, Input,
Textarea, Textarea,
Chip, Chip,
Switch,
Typography,
Breadcrumbs,
Link,
styled styled
} from '@/lib/mui' } from '@/lib/mui'
import moment from 'moment' import moment from 'moment'
import { InboxOutlined } from '@ant-design/icons' import { InboxOutlined } from '@ant-design/icons'
import CheckCircleOutlinedIcon from '@mui/icons-material/CheckCircleOutlined';
import type { UploadProps } from 'antd' import type { UploadProps } from 'antd'
import { Upload, Pagination, Popover, message } from 'antd' import { Upload, Pagination, Popover, message } from 'antd'
import { fetchBaseURL } from '@/app/datastores/constants' import { fetchBaseURL } from '@/app/datastores/constants'
@ -33,8 +38,8 @@ const Item = styled(Sheet)(({ theme }) => ({
color: theme.vars.palette.text.secondary color: theme.vars.palette.text.secondary
})) }))
const stepsOfAddingDocument = [ const stepsOfAddingDocument = [
'1.Choose a Datasource type', 'Choose a Datasource type',
'2.Setup the Datasource' 'Setup the Datasource'
] ]
const documentTypeList = [ const documentTypeList = [
{ {
@ -72,6 +77,7 @@ const Documents = () => {
const [originFileObj, setOriginFileObj] = useState<any>(null) const [originFileObj, setOriginFileObj] = useState<any>(null)
const [total, setTotal] = useState<number>(0) const [total, setTotal] = useState<number>(0)
const [current, setCurrent] = useState<number>(0) const [current, setCurrent] = useState<number>(0)
const [synchChecked, setSynchChecked] = useState<boolean>(true)
const props: UploadProps = { const props: UploadProps = {
name: 'file', name: 'file',
multiple: false, multiple: false,
@ -112,20 +118,33 @@ const Documents = () => {
}, []) }, [])
return ( return (
<div className="p-4"> <div className="p-4">
<Sheet <Stack
sx={{ direction="row"
display: 'flex', justifyContent="space-between"
flexDirection: 'row-reverse' alignItems="center"
}} sx={{ marginBottom: '20px' }}
> >
<Breadcrumbs aria-label="breadcrumbs">
<Link
onClick={() => {
router.push('/datastores')
}}
key="Knowledge Space"
underline="hover"
color="neutral"
fontSize="inherit"
>
Knowledge Space
</Link>
<Typography fontSize="inherit">Documents</Typography>
</Breadcrumbs>
<Button <Button
variant="outlined" variant="outlined"
onClick={() => setIsAddDocumentModalShow(true)} onClick={() => setIsAddDocumentModalShow(true)}
sx={{ marginBottom: '20px' }}
> >
+ Add Datasource + Add Datasource
</Button> </Button>
</Sheet> </Stack>
{documents.length ? ( {documents.length ? (
<> <>
<Table <Table
@ -334,7 +353,8 @@ const Documents = () => {
color: activeStep === index ? '#814DDE' : '' color: activeStep === index ? '#814DDE' : ''
}} }}
> >
{item} {index < activeStep ? <CheckCircleOutlinedIcon /> : `${index + 1}.`}
{`${item}`}
</Item> </Item>
))} ))}
</Stack> </Stack>
@ -422,7 +442,36 @@ const Documents = () => {
/> />
</> </>
)} )}
<Typography
component="label"
sx={{
marginTop: '20px'
}}
endDecorator={
<Switch
checked={synchChecked}
onChange={(event: any) =>
setSynchChecked(event.target.checked)
}
/>
}
>
Synch:
</Typography>
</Box> </Box>
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
sx={{ marginBottom: '20px' }}
>
<Button
variant="outlined"
sx={{ marginRight: '20px' }}
onClick={() => setActiveStep(0)}
>
{'< Back'}
</Button>
<Button <Button
variant="outlined" variant="outlined"
onClick={async () => { onClick={async () => {
@ -450,6 +499,20 @@ const Documents = () => {
} }
) )
const data = await res.json() const data = await res.json()
data.success &&
synchChecked &&
fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddDocumentModalShow(false) setIsAddDocumentModalShow(false)
@ -492,6 +555,20 @@ const Documents = () => {
} }
) )
const data = await res.json() const data = await res.json()
data.success &&
synchChecked &&
fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddDocumentModalShow(false) setIsAddDocumentModalShow(false)
@ -538,6 +615,20 @@ const Documents = () => {
} }
) )
const data = await res.json() const data = await res.json()
data.success &&
synchChecked &&
fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddDocumentModalShow(false) setIsAddDocumentModalShow(false)
@ -568,6 +659,7 @@ const Documents = () => {
> >
Finish Finish
</Button> </Button>
</Stack>
</> </>
)} )}
</Sheet> </Sheet>

View File

@ -3,6 +3,7 @@
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { InboxOutlined } from '@ant-design/icons' import { InboxOutlined } from '@ant-design/icons'
import CheckCircleOutlinedIcon from '@mui/icons-material/CheckCircleOutlined';
import type { UploadProps } from 'antd' import type { UploadProps } from 'antd'
import { message, Upload, Popover } from 'antd' import { message, Upload, Popover } from 'antd'
import { import {
@ -16,6 +17,8 @@ import {
Input, Input,
Textarea, Textarea,
Chip, Chip,
Switch,
Typography,
styled styled
} from '@/lib/mui' } from '@/lib/mui'
import { fetchBaseURL } from '@/app/datastores/constants' import { fetchBaseURL } from '@/app/datastores/constants'
@ -34,9 +37,9 @@ const Item = styled(Sheet)(({ theme }) => ({
})) }))
const stepsOfAddingSpace = [ const stepsOfAddingSpace = [
'1.Knowledge Space Config', 'Knowledge Space Config',
'2.Choose a Datasource type', 'Choose a Datasource type',
'3.Setup the Datasource' 'Setup the Datasource'
] ]
const documentTypeList = [ const documentTypeList = [
{ {
@ -71,6 +74,7 @@ const Index = () => {
const [textSource, setTextSource] = useState<string>('') const [textSource, setTextSource] = useState<string>('')
const [text, setText] = useState<string>('') const [text, setText] = useState<string>('')
const [originFileObj, setOriginFileObj] = useState<any>(null) const [originFileObj, setOriginFileObj] = useState<any>(null)
const [synchChecked, setSynchChecked] = useState<boolean>(true)
const props: UploadProps = { const props: UploadProps = {
name: 'file', name: 'file',
multiple: false, multiple: false,
@ -138,6 +142,9 @@ const Index = () => {
}, },
'& tbody tr: hover a': { '& tbody tr: hover a': {
textDecoration: 'underline' textDecoration: 'underline'
},
'& tbody tr a': {
color: 'rgb(13, 96, 217)'
} }
}} }}
> >
@ -214,9 +221,13 @@ const Index = () => {
{stepsOfAddingSpace.map((item: any, index: number) => ( {stepsOfAddingSpace.map((item: any, index: number) => (
<Item <Item
key={item} key={item}
sx={{ fontWeight: activeStep === index ? 'bold' : '', color: activeStep === index ? '#814DDE' : '' }} sx={{
fontWeight: activeStep === index ? 'bold' : '',
color: activeStep === index ? '#814DDE' : ''
}}
> >
{item} {index < activeStep ? <CheckCircleOutlinedIcon /> : `${index + 1}.`}
{`${item}`}
</Item> </Item>
))} ))}
</Stack> </Stack>
@ -361,9 +372,38 @@ const Index = () => {
/> />
</> </>
)} )}
<Typography
component="label"
sx={{
marginTop: '20px'
}}
endDecorator={
<Switch
checked={synchChecked}
onChange={(event: any) =>
setSynchChecked(event.target.checked)
}
/>
}
>
Synch:
</Typography>
</Box> </Box>
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
sx={{ marginBottom: '20px' }}
>
<Button <Button
variant='outlined' variant="outlined"
sx={{ marginRight: '20px' }}
onClick={() => setActiveStep(1)}
>
{'< Back'}
</Button>
<Button
variant="outlined"
onClick={async () => { onClick={async () => {
if (documentName === '') { if (documentName === '') {
message.error('Please input the name') message.error('Please input the name')
@ -392,6 +432,19 @@ const Index = () => {
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddKnowledgeSpaceModalShow(false) setIsAddKnowledgeSpaceModalShow(false)
synchChecked &&
fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else { } else {
message.error(data.err_msg || 'failed') message.error(data.err_msg || 'failed')
} }
@ -415,6 +468,19 @@ const Index = () => {
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddKnowledgeSpaceModalShow(false) setIsAddKnowledgeSpaceModalShow(false)
synchChecked &&
fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else { } else {
message.error(data.err_msg || 'failed') message.error(data.err_msg || 'failed')
} }
@ -442,6 +508,19 @@ const Index = () => {
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddKnowledgeSpaceModalShow(false) setIsAddKnowledgeSpaceModalShow(false)
synchChecked &&
fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else { } else {
message.error(data.err_msg || 'failed') message.error(data.err_msg || 'failed')
} }
@ -450,6 +529,7 @@ const Index = () => {
> >
Finish Finish
</Button> </Button>
</Stack>
</> </>
)} )}
</Sheet> </Sheet>