From 679453372eeb36dc9abbcccf36a044ed0e76724a Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Mon, 25 Aug 2025 14:50:33 +0800 Subject: [PATCH] feat: Whether the document support settings of the General Knowledge Base and Feishu Knowledge Base allow downloading (#3924) --- .../reranker_node/impl/base_reranker_node.py | 13 +++++++++++-- .../impl/base_search_knowledge_node.py | 9 ++++++++- .../knowledge-source-component/ParagraphCard.vue | 10 +++++++--- .../component/knowledge-source-component/index.vue | 10 +++++++--- ui/src/locales/lang/en-US/ai-chat.ts | 1 + ui/src/locales/lang/zh-CN/ai-chat.ts | 1 + ui/src/locales/lang/zh-Hant/ai-chat.ts | 1 + 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/apps/application/flow/step_node/reranker_node/impl/base_reranker_node.py b/apps/application/flow/step_node/reranker_node/impl/base_reranker_node.py index 946399e70..58492d305 100644 --- a/apps/application/flow/step_node/reranker_node/impl/base_reranker_node.py +++ b/apps/application/flow/step_node/reranker_node/impl/base_reranker_node.py @@ -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, diff --git a/apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py b/apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py index ddbe67598..176b7a99e 100644 --- a/apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py +++ b/apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py @@ -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 diff --git a/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphCard.vue b/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphCard.vue index e6d3e985e..73ca64060 100644 --- a/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphCard.vue +++ b/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphCard.vue @@ -37,7 +37,7 @@ {{ data?.document_name }} -