Skip to content

Commit 6794533

Browse files
authored
feat: Whether the document support settings of the General Knowledge Base and Feishu Knowledge Base allow downloading (#3924)
1 parent 64e9a29 commit 6794533

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

apps/application/flow/step_node/reranker_node/impl/base_reranker_node.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ def get_none_result(question):
6767
'result_list': [], 'result': ''}, {})
6868

6969

70+
def reset_metadata(metadata):
71+
meta = metadata.get('meta')
72+
if isinstance(metadata.get('meta'), dict):
73+
if not meta.get('allow_download', False):
74+
metadata['meta'] = {'allow_download': False}
75+
return metadata
76+
77+
7078
class BaseRerankerNode(IRerankerNode):
7179
def save_context(self, details, workflow_manage):
7280
self.context['document_list'] = details.get('document_list', [])
@@ -83,8 +91,9 @@ def execute(self, question, reranker_setting, reranker_list, reranker_model_id,
8391
if len(documents) == 0:
8492
return get_none_result(question)
8593
top_n = reranker_setting.get('top_n', 3)
86-
self.context['document_list'] = [{'page_content': document.page_content, 'metadata': document.metadata} for
87-
document in documents]
94+
self.context['document_list'] = [
95+
{'page_content': document.page_content, 'metadata': reset_metadata(document.metadata)} for
96+
document in documents]
8897
self.context['question'] = question
8998
workspace_id = self.workflow_manage.get_body().get('workspace_id')
9099
reranker_model = get_model_instance_by_model_workspace_id(reranker_model_id,

apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def reset_title(title):
4646
return f"#### {title}\n"
4747

4848

49+
def reset_meta(meta):
50+
if not meta.get('allow_download', False):
51+
return {'allow_download': False}
52+
return meta
53+
54+
4955
class BaseSearchKnowledgeNode(ISearchKnowledgeStepNode):
5056
def save_context(self, details, workflow_manage):
5157
result = details.get('paragraph_list', [])
@@ -122,7 +128,8 @@ def reset_paragraph(paragraph: Dict, embedding_list: List):
122128
'create_time': paragraph.get('create_time').strftime("%Y-%m-%d %H:%M:%S"),
123129
'id': str(paragraph.get('id')),
124130
'knowledge_id': str(paragraph.get('knowledge_id')),
125-
'document_id': str(paragraph.get('document_id'))
131+
'document_id': str(paragraph.get('document_id')),
132+
'meta': reset_meta(paragraph.get('meta'))
126133
}
127134

128135
@staticmethod

ui/src/components/ai-chat/component/knowledge-source-component/ParagraphCard.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<span :title="data?.document_name?.trim()">{{ data?.document_name }}</span>
3838
</a>
3939
</div>
40-
<div v-else @click="infoMessage">
40+
<div v-else @click="infoMessage(data)">
4141
<span class="ellipsis-1 break-all" :title="data?.document_name?.trim()">
4242
{{ data?.document_name?.trim() }}
4343
</span>
@@ -87,8 +87,12 @@ const parsedMeta = computed(() => {
8787
})
8888
8989
const meta = computed(() => (isMetaObject.value ? props.data.meta : parsedMeta.value))
90-
function infoMessage() {
91-
MsgInfo(t('chat.noDocument'))
90+
function infoMessage(data: any) {
91+
if (data?.meta?.allow_download === false) {
92+
MsgInfo(t('chat.noPermissionDownload'))
93+
} else {
94+
MsgInfo(t('chat.noDocument'))
95+
}
9296
}
9397
</script>
9498
<style lang="scss" scoped></style>

ui/src/components/ai-chat/component/knowledge-source-component/index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<span :title="item?.document_name?.trim()">{{ item?.document_name }}</span>
4646
</a>
4747
</div>
48-
<div v-else @click="infoMessage">
48+
<div v-else @click="infoMessage(item)">
4949
<span class="ellipsis-1 break-all" :title="item?.document_name?.trim()">
5050
{{ item?.document_name?.trim() }}
5151
</span>
@@ -167,8 +167,12 @@ const currentComponent = shallowRef<any>(null)
167167
const currentChatDetail = ref<any>(null)
168168
const dialogType = ref('')
169169
170-
function infoMessage() {
171-
MsgInfo(t('chat.noDocument'))
170+
function infoMessage(data: any) {
171+
if (data?.meta?.allow_download === false) {
172+
MsgInfo(t('chat.noPermissionDownload'))
173+
} else {
174+
MsgInfo(t('chat.noDocument'))
175+
}
172176
}
173177
function openParagraph(row: any, id?: string) {
174178
dialogTitle.value = t('chat.KnowledgeSource.title')

ui/src/locales/lang/en-US/ai-chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
quote: 'Quote',
1515
download: 'Click to Download',
1616
noDocument: 'Original Document Not Found',
17+
noPermissionDownload: 'No permission to download',
1718
passwordValidator: {
1819
title: 'Enter Password to Access',
1920
errorMessage1: 'Password cannot be empty',

ui/src/locales/lang/zh-CN/ai-chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818
download: '点击下载文件',
1919
transcribing: '转文字中',
2020
noDocument: '原文档不存在',
21+
noPermissionDownload: '无权限下载',
2122
passwordValidator: {
2223
title: '请输入密码打开链接',
2324
errorMessage1: '密码不能为空',

ui/src/locales/lang/zh-Hant/ai-chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
quote: '引用',
1515
download: '點擊下載文件',
1616
noDocument: '原文檔不存在',
17+
noPermissionDownload: '無許可權下載',
1718
passwordValidator: {
1819
title: '請輸入密碼打開連結',
1920
errorMessage1: '密碼不能為空',

0 commit comments

Comments
 (0)