diff --git a/apps/application/chat_pipeline/I_base_chat_pipeline.py b/apps/application/chat_pipeline/I_base_chat_pipeline.py index 4c894ddbd..a35bdc39c 100644 --- a/apps/application/chat_pipeline/I_base_chat_pipeline.py +++ b/apps/application/chat_pipeline/I_base_chat_pipeline.py @@ -19,7 +19,7 @@ class ParagraphPipelineModel: def __init__(self, _id: str, document_id: str, dataset_id: str, content: str, title: str, status: str, is_active: bool, comprehensive_score: float, similarity: float, dataset_name: str, document_name: str, - hit_handling_method: str, directly_return_similarity: float): + hit_handling_method: str, directly_return_similarity: float, meta: dict = None): self.id = _id self.document_id = document_id self.dataset_id = dataset_id @@ -33,6 +33,7 @@ class ParagraphPipelineModel: self.document_name = document_name self.hit_handling_method = hit_handling_method self.directly_return_similarity = directly_return_similarity + self.meta = meta def to_dict(self): return { @@ -46,7 +47,8 @@ class ParagraphPipelineModel: 'comprehensive_score': self.comprehensive_score, 'similarity': self.similarity, 'dataset_name': self.dataset_name, - 'document_name': self.document_name + 'document_name': self.document_name, + 'meta': self.meta, } class builder: @@ -58,6 +60,7 @@ class ParagraphPipelineModel: self.dataset_name = None self.hit_handling_method = None self.directly_return_similarity = 0.9 + self.meta = {} def add_paragraph(self, paragraph): if isinstance(paragraph, Paragraph): @@ -97,6 +100,10 @@ class ParagraphPipelineModel: self.similarity = similarity return self + def add_meta(self, meta: dict): + self.meta = meta + return self + def build(self): return ParagraphPipelineModel(str(self.paragraph.get('id')), str(self.paragraph.get('document_id')), str(self.paragraph.get('dataset_id')), @@ -104,7 +111,8 @@ class ParagraphPipelineModel: self.paragraph.get('status'), self.paragraph.get('is_active'), self.comprehensive_score, self.similarity, self.dataset_name, - self.document_name, self.hit_handling_method, self.directly_return_similarity) + self.document_name, self.hit_handling_method, self.directly_return_similarity, + self.meta) class IBaseChatPipelineStep: diff --git a/apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py b/apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py index c13b414dc..69d1ee501 100644 --- a/apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py +++ b/apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py @@ -79,6 +79,7 @@ class BaseSearchDatasetStep(ISearchDatasetStep): .add_document_name(paragraph.get('document_name')) .add_hit_handling_method(paragraph.get('hit_handling_method')) .add_directly_return_similarity(paragraph.get('directly_return_similarity')) + .add_meta(paragraph.get('meta')) .build()) @staticmethod diff --git a/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py b/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py index f450a1dd0..3cb1d601c 100644 --- a/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py +++ b/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py @@ -40,7 +40,7 @@ class BaseDocumentExtractNode(IDocumentExtractNode): "index": index, 'run_time': self.context.get('run_time'), 'type': self.node.type, - 'content': self.context.get('content'), + # 'content': self.context.get('content'), # 不保存content内容,因为content内容可能会很大 'status': self.status, 'err_message': self.err_message, 'document_list': self.context.get('document_list') diff --git a/apps/application/flow/step_node/image_understand_step_node/impl/base_image_understand_node.py b/apps/application/flow/step_node/image_understand_step_node/impl/base_image_understand_node.py index 16aafb628..813cd3158 100644 --- a/apps/application/flow/step_node/image_understand_step_node/impl/base_image_understand_node.py +++ b/apps/application/flow/step_node/image_understand_step_node/impl/base_image_understand_node.py @@ -67,11 +67,13 @@ class BaseImageUnderstandNode(IImageUnderstandNode): image, **kwargs) -> NodeResult: image_model = get_model_instance_by_model_user_id(model_id, self.flow_params_serializer.data.get('user_id')) - history_message = self.get_history_message(history_chat_record, dialogue_number) + # 执行详情中的历史消息不需要图片内容 + history_message =self.get_history_message_for_details(history_chat_record, dialogue_number) self.context['history_message'] = history_message question = self.generate_prompt_question(prompt) self.context['question'] = question.content - message_list = self.generate_message_list(image_model, system, prompt, history_message, image) + # 生成消息列表, 真实的history_message + message_list = self.generate_message_list(image_model, system, prompt, self.get_history_message(history_chat_record, dialogue_number), image) self.context['message_list'] = message_list self.context['image_list'] = image self.context['dialogue_type'] = dialogue_type @@ -86,6 +88,15 @@ class BaseImageUnderstandNode(IImageUnderstandNode): 'history_message': history_message, 'question': question.content}, {}, _write_context=write_context) + @staticmethod + def get_history_message_for_details(history_chat_record, dialogue_number): + start_index = len(history_chat_record) - dialogue_number + history_message = reduce(lambda x, y: [*x, *y], [ + [history_chat_record[index].get_human_message(), history_chat_record[index].get_ai_message()] + for index in + range(start_index if start_index > 0 else 0, len(history_chat_record))], []) + return history_message + def get_history_message(self, history_chat_record, dialogue_number): start_index = len(history_chat_record) - dialogue_number history_message = reduce(lambda x, y: [*x, *y], [ diff --git a/apps/application/sql/list_dataset_paragraph_by_paragraph_id.sql b/apps/application/sql/list_dataset_paragraph_by_paragraph_id.sql index 2bacd53e1..803b6307e 100644 --- a/apps/application/sql/list_dataset_paragraph_by_paragraph_id.sql +++ b/apps/application/sql/list_dataset_paragraph_by_paragraph_id.sql @@ -2,6 +2,7 @@ SELECT paragraph.*, dataset."name" AS "dataset_name", "document"."name" AS "document_name", + "document"."meta" AS "meta", "document"."hit_handling_method" AS "hit_handling_method", "document"."directly_return_similarity" as "directly_return_similarity" FROM diff --git a/ui/src/components/ai-chat/ExecutionDetailDialog.vue b/ui/src/components/ai-chat/ExecutionDetailDialog.vue index 2b8de6545..ef7ce1b73 100644 --- a/ui/src/components/ai-chat/ExecutionDetailDialog.vue +++ b/ui/src/components/ai-chat/ExecutionDetailDialog.vue @@ -28,7 +28,7 @@