mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: Whether the document support settings of the General Knowledge Base and Feishu Knowledge Base allow downloading (#3924)
This commit is contained in:
parent
64e9a29a60
commit
679453372e
|
|
@ -67,6 +67,14 @@ def get_none_result(question):
|
|||
'result_list': [], 'result': ''}, {})
|
||||
|
||||
|
||||
def reset_metadata(metadata):
|
||||
meta = metadata.get('meta')
|
||||
if isinstance(metadata.get('meta'), dict):
|
||||
if not meta.get('allow_download', False):
|
||||
metadata['meta'] = {'allow_download': False}
|
||||
return metadata
|
||||
|
||||
|
||||
class BaseRerankerNode(IRerankerNode):
|
||||
def save_context(self, details, workflow_manage):
|
||||
self.context['document_list'] = details.get('document_list', [])
|
||||
|
|
@ -83,8 +91,9 @@ class BaseRerankerNode(IRerankerNode):
|
|||
if len(documents) == 0:
|
||||
return get_none_result(question)
|
||||
top_n = reranker_setting.get('top_n', 3)
|
||||
self.context['document_list'] = [{'page_content': document.page_content, 'metadata': document.metadata} for
|
||||
document in documents]
|
||||
self.context['document_list'] = [
|
||||
{'page_content': document.page_content, 'metadata': reset_metadata(document.metadata)} for
|
||||
document in documents]
|
||||
self.context['question'] = question
|
||||
workspace_id = self.workflow_manage.get_body().get('workspace_id')
|
||||
reranker_model = get_model_instance_by_model_workspace_id(reranker_model_id,
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ def reset_title(title):
|
|||
return f"#### {title}\n"
|
||||
|
||||
|
||||
def reset_meta(meta):
|
||||
if not meta.get('allow_download', False):
|
||||
return {'allow_download': False}
|
||||
return meta
|
||||
|
||||
|
||||
class BaseSearchKnowledgeNode(ISearchKnowledgeStepNode):
|
||||
def save_context(self, details, workflow_manage):
|
||||
result = details.get('paragraph_list', [])
|
||||
|
|
@ -122,7 +128,8 @@ class BaseSearchKnowledgeNode(ISearchKnowledgeStepNode):
|
|||
'create_time': paragraph.get('create_time').strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'id': str(paragraph.get('id')),
|
||||
'knowledge_id': str(paragraph.get('knowledge_id')),
|
||||
'document_id': str(paragraph.get('document_id'))
|
||||
'document_id': str(paragraph.get('document_id')),
|
||||
'meta': reset_meta(paragraph.get('meta'))
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
<span :title="data?.document_name?.trim()">{{ data?.document_name }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div v-else @click="infoMessage">
|
||||
<div v-else @click="infoMessage(data)">
|
||||
<span class="ellipsis-1 break-all" :title="data?.document_name?.trim()">
|
||||
{{ data?.document_name?.trim() }}
|
||||
</span>
|
||||
|
|
@ -87,8 +87,12 @@ const parsedMeta = computed(() => {
|
|||
})
|
||||
|
||||
const meta = computed(() => (isMetaObject.value ? props.data.meta : parsedMeta.value))
|
||||
function infoMessage() {
|
||||
MsgInfo(t('chat.noDocument'))
|
||||
function infoMessage(data: any) {
|
||||
if (data?.meta?.allow_download === false) {
|
||||
MsgInfo(t('chat.noPermissionDownload'))
|
||||
} else {
|
||||
MsgInfo(t('chat.noDocument'))
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped></style>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
<span :title="item?.document_name?.trim()">{{ item?.document_name }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div v-else @click="infoMessage">
|
||||
<div v-else @click="infoMessage(item)">
|
||||
<span class="ellipsis-1 break-all" :title="item?.document_name?.trim()">
|
||||
{{ item?.document_name?.trim() }}
|
||||
</span>
|
||||
|
|
@ -167,8 +167,12 @@ const currentComponent = shallowRef<any>(null)
|
|||
const currentChatDetail = ref<any>(null)
|
||||
const dialogType = ref('')
|
||||
|
||||
function infoMessage() {
|
||||
MsgInfo(t('chat.noDocument'))
|
||||
function infoMessage(data: any) {
|
||||
if (data?.meta?.allow_download === false) {
|
||||
MsgInfo(t('chat.noPermissionDownload'))
|
||||
} else {
|
||||
MsgInfo(t('chat.noDocument'))
|
||||
}
|
||||
}
|
||||
function openParagraph(row: any, id?: string) {
|
||||
dialogTitle.value = t('chat.KnowledgeSource.title')
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export default {
|
|||
quote: 'Quote',
|
||||
download: 'Click to Download',
|
||||
noDocument: 'Original Document Not Found',
|
||||
noPermissionDownload: 'No permission to download',
|
||||
passwordValidator: {
|
||||
title: 'Enter Password to Access',
|
||||
errorMessage1: 'Password cannot be empty',
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export default {
|
|||
download: '点击下载文件',
|
||||
transcribing: '转文字中',
|
||||
noDocument: '原文档不存在',
|
||||
noPermissionDownload: '无权限下载',
|
||||
passwordValidator: {
|
||||
title: '请输入密码打开链接',
|
||||
errorMessage1: '密码不能为空',
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export default {
|
|||
quote: '引用',
|
||||
download: '點擊下載文件',
|
||||
noDocument: '原文檔不存在',
|
||||
noPermissionDownload: '無許可權下載',
|
||||
passwordValidator: {
|
||||
title: '請輸入密碼打開連結',
|
||||
errorMessage1: '密碼不能為空',
|
||||
|
|
|
|||
Loading…
Reference in New Issue