mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-10 12:42:34 +00:00
feat: expand types of documents
This commit is contained in:
parent
3db734a01e
commit
db5f35d334
@ -1,8 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import type { ProFormInstance } from '@ant-design/pro-components'
|
import React, { useState, useEffect } from 'react'
|
||||||
import React, { useState, useRef, useEffect } from 'react'
|
|
||||||
import { message } from 'antd'
|
import { message } from 'antd'
|
||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
@ -31,16 +30,33 @@ const stepsOfAddingSpace = [
|
|||||||
'Choose a Datasource type',
|
'Choose a Datasource type',
|
||||||
'Setup the Datasource'
|
'Setup the Datasource'
|
||||||
]
|
]
|
||||||
|
const documentTypeList = [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
title: 'Text',
|
||||||
|
subTitle: 'Paste some text'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'webPage',
|
||||||
|
title: 'Web Page',
|
||||||
|
subTitle: 'Crawl text from a web page'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'file',
|
||||||
|
title: 'File',
|
||||||
|
subTitle: 'It can be: PDF, CSV, JSON, Text, PowerPoint, Word, Excel'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const formRef = useRef<ProFormInstance>()
|
|
||||||
const [activeStep, setActiveStep] = useState<number>(0)
|
const [activeStep, setActiveStep] = useState<number>(0)
|
||||||
const [knowledgeSpaceList, setKnowledgeSpaceList] = useState<any>([])
|
const [knowledgeSpaceList, setKnowledgeSpaceList] = useState<any>([])
|
||||||
const [isAddKnowledgeSpaceModalShow, setIsAddKnowledgeSpaceModalShow] =
|
const [isAddKnowledgeSpaceModalShow, setIsAddKnowledgeSpaceModalShow] =
|
||||||
useState<boolean>(false)
|
useState<boolean>(false)
|
||||||
const [knowledgeSpaceName, setKnowledgeSpaceName] = useState<string>('')
|
const [knowledgeSpaceName, setKnowledgeSpaceName] = useState<string>('')
|
||||||
const [webPageUrl, setWebPageUrl] = useState<string>('')
|
const [webPageUrl, setWebPageUrl] = useState<string>('')
|
||||||
|
const [documentName, setDocumentName] = useState<string>('')
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const res = await fetch('http://localhost:8000/knowledge/space/list', {
|
const res = await fetch('http://localhost:8000/knowledge/space/list', {
|
||||||
@ -191,14 +207,42 @@ const Index = () => {
|
|||||||
) : activeStep === 1 ? (
|
) : activeStep === 1 ? (
|
||||||
<>
|
<>
|
||||||
<Box sx={{ margin: '30px auto' }}>
|
<Box sx={{ margin: '30px auto' }}>
|
||||||
<Button variant="outlined" onClick={() => setActiveStep(2)}>
|
{documentTypeList.map((item: any) => (
|
||||||
Web Page
|
<Sheet
|
||||||
</Button>
|
key={item.type}
|
||||||
|
sx={{
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
height: '80px',
|
||||||
|
padding: '12px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
border: '1px solid gray',
|
||||||
|
borderRadius: '6px',
|
||||||
|
marginBottom: '20px',
|
||||||
|
cursor: 'pointer'
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
if (item.type === 'webPage') {
|
||||||
|
setActiveStep(2);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Sheet sx={{ fontSize: '20px', fontWeight: 'bold' }}>{item.title}</Sheet>
|
||||||
|
<Sheet>{item.subTitle}</Sheet>
|
||||||
|
</Sheet>
|
||||||
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Box sx={{ margin: '30px auto' }}>
|
<Box sx={{ margin: '30px auto' }}>
|
||||||
|
Name:
|
||||||
|
<Input
|
||||||
|
placeholder="Please input the name"
|
||||||
|
onChange={(e: any) => setDocumentName(e.target.value)}
|
||||||
|
sx={{ marginBottom: '20px'}}
|
||||||
|
/>
|
||||||
Web Page URL:
|
Web Page URL:
|
||||||
<Input
|
<Input
|
||||||
placeholder="Please input the Web Page URL"
|
placeholder="Please input the Web Page URL"
|
||||||
@ -207,6 +251,14 @@ const Index = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
|
if (documentName === '') {
|
||||||
|
message.error('Please input the name');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (webPageUrl === '') {
|
||||||
|
message.error('Please input the Web Page URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`http://localhost:8000/knowledge/${knowledgeSpaceName}/document/add`,
|
`http://localhost:8000/knowledge/${knowledgeSpaceName}/document/add`,
|
||||||
{
|
{
|
||||||
@ -215,7 +267,8 @@ const Index = () => {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
doc_name: webPageUrl,
|
doc_name: documentName,
|
||||||
|
content: webPageUrl,
|
||||||
doc_type: 'URL'
|
doc_type: 'URL'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user