Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jinchat-server
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
aigc-pioneer
jinchat-server
Commits
ff8cecd7
Unverified
提交
ff8cecd7
authored
5月 15, 2023
作者:
fxjhello
提交者:
GitHub
5月 15, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #365 from halfss/dev
add Knowledge Base delete and file delete
上级
228e460b
2563b16a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
18 行删除
+46
-18
api.py
api.py
+9
-5
filelist.vue
...s/src/views/chat/layout/sider/knowledge-base/filelist.vue
+6
-10
index.vue
views/src/views/chat/layout/sider/knowledge-base/index.vue
+31
-3
没有找到文件。
api.py
浏览文件 @
ff8cecd7
...
...
@@ -3,6 +3,7 @@ import json
import
os
import
shutil
from
typing
import
List
,
Optional
import
urllib
import
nltk
import
pydantic
...
...
@@ -169,24 +170,27 @@ async def list_docs(
async
def
delete_docs
(
knowledge_base_id
:
str
=
Form
(
...
,
knowledge_base_id
:
str
=
Query
(
...
,
description
=
"Knowledge Base Name(注意此方法仅删除上传的文件并不会删除知识库(FAISS)内数据)"
,
example
=
"kb1"
),
doc_name
:
Optional
[
str
]
=
Form
(
doc_name
:
Optional
[
str
]
=
Query
(
None
,
description
=
"doc name"
,
example
=
"doc_name_1.pdf"
),
):
knowledge_base_id
=
urllib
.
parse
.
unquote
(
knowledge_base_id
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
UPLOAD_ROOT_PATH
,
knowledge_base_id
)):
return
{
"code"
:
1
,
"msg"
:
f
"Knowledge base {knowledge_base_id} not found"
}
if
doc_name
:
doc_path
=
get_file_path
(
knowledge_base_id
,
doc_name
)
if
os
.
path
.
exists
(
doc_path
):
os
.
remove
(
doc_path
)
return
BaseResponse
(
code
=
200
,
msg
=
f
"document {doc_name} delete success"
)
else
:
BaseResponse
(
code
=
1
,
msg
=
f
"document {doc_name} not found"
)
return
BaseResponse
(
code
=
1
,
msg
=
f
"document {doc_name} not found"
)
remain_docs
=
await
list_docs
(
knowledge_base_id
)
if
remain_docs
[
"code"
]
!=
0
or
len
(
remain_docs
[
"data"
])
==
0
:
remain_docs
=
remain_docs
.
json
()
if
len
(
remain_docs
[
"data"
])
==
0
:
shutil
.
rmtree
(
get_folder_path
(
knowledge_base_id
),
ignore_errors
=
True
)
else
:
local_doc_qa
.
init_knowledge_vector_store
(
...
...
@@ -194,7 +198,7 @@ async def delete_docs(
)
else
:
shutil
.
rmtree
(
get_folder_path
(
knowledge_base_id
))
return
BaseResponse
(
)
return
BaseResponse
(
code
=
200
,
msg
=
f
"Knowledge Base {knowledge_base_id} delete success"
)
async
def
local_doc_chat
(
...
...
views/src/views/chat/layout/sider/knowledge-base/filelist.vue
浏览文件 @
ff8cecd7
...
...
@@ -25,7 +25,7 @@ onMounted(async () => {
} */
async
function
handleDelete
(
item
:
any
)
{
/* const mid = */
await
deletefile
(
{
knowledge_base_id
:
knowledge_base_id
.
value
,
doc_name
:
item
}
)
/* const mid = */
await
deletefile
(
knowledge_base_id
.
value
,
item
)
const
res
=
await
getfilelist
(
knowledge_base_id
.
value
)
dataSources
.
value
=
res
.
data
.
data
}
...
...
@@ -35,7 +35,6 @@ function handleEnter({ uuid }: Chat.History, isEdit: boolean, event: KeyboardEve
if
(
event
.
key
===
'Enter'
)
chatStore
.
updateHistory
(
uuid
,
{
isEdit
})
}
console
.
log
(
`
${
web_url
()}
/api/local_doc_qa/upload_file`
)
</
script
>
<
template
>
...
...
@@ -51,11 +50,6 @@ console.log(`${web_url()}/api/local_doc_qa/upload_file`)
}"
>
<NUploadDragger>
<!--
<div
style=
"margin-bottom: 12px"
>
<NIcon
size=
"48"
:depth=
"3"
>
<archive-icon
/>
</NIcon>
</div>
-->
<NText
style=
"font-size: 16px"
>
点击或者拖动文件到该区域来上传
</NText>
...
...
@@ -73,8 +67,9 @@ console.log(`${web_url()}/api/local_doc_qa/upload_file`)
</div>
</
template
>
<
template
v-else
>
<div
v-for=
"(item, index) of dataSources"
:key=
"index"
>
<div
v-for=
"(item, index) of dataSources"
:key=
"index"
class=
"flex items-center"
>
<a
style=
"width:90%"
class=
"relative flex items-center gap-3 px-3 py-3 break-all border rounded-md cursor-pointer hover:bg-neutral-100 group dark:border-neutral-800 dark:hover:bg-[#24272e]"
>
<span>
...
...
@@ -88,6 +83,8 @@ console.log(`${web_url()}/api/local_doc_qa/upload_file`)
/>
<span
v-else
>
{{
item
}}
</span>
</div>
</a>
<div
class=
"absolute z-10 flex visible right-1"
>
<template
v-if=
"item.isEdit"
>
<!--
<button
class=
"p-1"
@
click=
"handleEdit(item, false, $event)"
>
...
...
@@ -101,14 +98,13 @@ console.log(`${web_url()}/api/local_doc_qa/upload_file`)
<NPopconfirm
placement=
"bottom"
@
positive-click=
"handleDelete(item)"
>
<template
#
trigger
>
<button
class=
"p-1"
>
<!--
<SvgIcon
icon=
"ri:delete-bin-line"
/>
--
>
<SvgIcon
icon=
"ri:delete-bin-line"
/
>
</button>
</
template
>
确定删除此文件?
</NPopconfirm>
</template>
</div>
</a>
</div>
</template>
</div>
...
...
views/src/views/chat/layout/sider/knowledge-base/index.vue
浏览文件 @
ff8cecd7
<
script
setup
lang=
'ts'
>
import
{
NButton
,
NForm
,
NFormItem
,
NInput
}
from
'naive-ui'
import
{
NButton
,
NForm
,
NFormItem
,
NInput
,
NPopconfirm
}
from
'naive-ui'
import
{
onMounted
,
ref
}
from
'vue'
import
filelist
from
'./filelist.vue'
import
{
getfilelist
}
from
'@/api/chat'
import
{
SvgIcon
}
from
'@/components/common'
import
{
deletefile
,
getfilelist
}
from
'@/api/chat'
import
{
idStore
}
from
'@/store/modules/knowledgebaseid/id'
const
items
=
ref
<
any
>
([])
const
choice
=
ref
(
''
)
...
...
@@ -51,6 +52,17 @@ const handleClick = () => {
})
}
}
async
function
handleDelete
(
item
:
any
)
{
await
deletefile
(
item
.
value
)
const
res
=
await
getfilelist
({})
items
.
value
=
[]
res
.
data
.
data
.
forEach
((
item
:
any
)
=>
{
items
.
value
.
push
({
value
:
item
,
show
:
false
,
})
})
}
</
script
>
<
template
>
...
...
@@ -74,9 +86,25 @@ const handleClick = () => {
</NFormItem>
</NForm>
<div
v-for=
"item in items"
:key=
"item.value"
>
<NButton
block
size=
"large"
@
click=
"handleValidateClick(item.value)"
>
<div
class=
"flex items-center"
>
<NButton
block
size=
"large"
style=
"width:90%"
@
click=
"handleValidateClick(item.value)"
>
{{
item
.
value
}}
</NButton>
<div
class=
"absolute z-10 flex visible right-1"
>
<template
v-if=
"item.isEdit"
/>
<template
v-else
>
<NPopconfirm
placement=
"bottom"
@
positive-click=
"handleDelete(item)"
>
<template
#
trigger
>
<button
class=
"p-1"
>
<SvgIcon
icon=
"ri:delete-bin-line"
/>
</button>
</
template
>
确定删除此文件?
</NPopconfirm>
</template>
</div>
</div>
<div
v-if=
"item.show"
class=
"p-2 flex-1 min-h-0 pb-4 overflow-hidden"
>
<filelist
v-if=
"item.value"
:knowledgebaseid=
"item.value"
/>
</div>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论