diff --git a/apps/application/chat_pipeline/step/chat_step/i_chat_step.py b/apps/application/chat_pipeline/step/chat_step/i_chat_step.py index b19a52666..9bb33b0fe 100644 --- a/apps/application/chat_pipeline/step/chat_step/i_chat_step.py +++ b/apps/application/chat_pipeline/step/chat_step/i_chat_step.py @@ -69,6 +69,7 @@ class IChatStep(IBaseChatPipelineStep): # 是否使用流的形式输出 stream = serializers.BooleanField(required=False, label=_("Streaming Output")) chat_user_id = serializers.CharField(required=True, label=_("Chat user id")) + chat_record_id = serializers.CharField(required=False, label=_("Chat record id")) chat_user_type = serializers.CharField(required=True, label=_("Chat user Type")) # 未查询到引用分段 diff --git a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py index 3dfbb6834..f42241c68 100644 --- a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py +++ b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py @@ -351,7 +351,7 @@ class BaseChatStep(IChatStep): mcp_servers, mcp_source, tool_enable, tool_ids, application_enable, application_ids, mcp_output_enable) - chat_record_id = uuid.uuid7() + chat_record_id = self.context.get('step_args',{}).get('chat_record_id') if self.context.get('step_args',{}).get('chat_record_id') else uuid.uuid7() r = StreamingHttpResponse( streaming_content=event_content(chat_result, chat_id, chat_record_id, paragraph_list, post_response_handler, manage, self, chat_model, message_list, problem_text, diff --git a/apps/application/flow/i_step_node.py b/apps/application/flow/i_step_node.py index e8caf162d..2ae2af6e4 100644 --- a/apps/application/flow/i_step_node.py +++ b/apps/application/flow/i_step_node.py @@ -64,6 +64,7 @@ class WorkFlowPostHandler: answer_text_list) if workflow.chat_record is not None: chat_record = workflow.chat_record + chat_record.problem_text = question chat_record.answer_text = answer_text chat_record.details = details chat_record.message_tokens = message_tokens diff --git a/apps/application/flow/workflow_manage.py b/apps/application/flow/workflow_manage.py index 21bacb65a..b10e5c597 100644 --- a/apps/application/flow/workflow_manage.py +++ b/apps/application/flow/workflow_manage.py @@ -563,7 +563,7 @@ class WorkflowManage: details_result = {} for index in range(len(self.node_context)): node = self.node_context[index] - if self.chat_record is not None and self.chat_record.details is not None: + if self.chat_record is not None and self.chat_record.details is not None and self.start_node: details = self.chat_record.details.get(node.runtime_node_id) if details is not None and self.start_node.runtime_node_id != node.runtime_node_id: details_result[node.runtime_node_id] = details diff --git a/apps/chat/serializers/chat.py b/apps/chat/serializers/chat.py index 69c6bf07c..6a1cb00ee 100644 --- a/apps/chat/serializers/chat.py +++ b/apps/chat/serializers/chat.py @@ -327,6 +327,7 @@ class ChatSerializers(serializers.Serializer): chat_user_id = self.data.get('chat_user_id') chat_user_type = self.data.get('chat_user_type') form_data = instance.get("form_data") + chat_record_id = instance.get('chat_record_id') pipeline_manage_builder = PipelineManage.builder() # 如果开启了问题优化,则添加上问题优化步骤 if chat_info.application.problem_optimization: @@ -350,6 +351,8 @@ class ChatSerializers(serializers.Serializer): # 构建运行参数 params = chat_info.to_pipeline_manage_params(message, get_post_handler(chat_info), exclude_paragraph_id_list, chat_user_id, chat_user_type, stream, form_data) + if chat_record_id: + params['chat_record_id'] = chat_record_id chat_info.set_chat(message) # 运行流水线作业 pipeline_message.run(params) diff --git a/ui/src/components/ai-chat/component/question-content/index.vue b/ui/src/components/ai-chat/component/question-content/index.vue index e6b3dab0f..53bf56200 100644 --- a/ui/src/components/ai-chat/component/question-content/index.vue +++ b/ui/src/components/ai-chat/component/question-content/index.vue @@ -1,7 +1,7 @@