55import uuid_utils .compat as uuid
66from django .db .models import QuerySet
77
8+ from application .flow .common import WorkflowMode
89from application .flow .i_step_node import NodeResult
910from application .flow .step_node .document_extract_node .i_document_extract_node import IDocumentExtractNode
1011from knowledge .models import File , FileSourceType
@@ -28,30 +29,34 @@ def execute(self, document, chat_id=None, **kwargs):
2829
2930 # 安全获取 application
3031 application_id = None
31- if (self .workflow_manage and
32- self .workflow_manage .work_flow_post_handler and
33- self .workflow_manage .work_flow_post_handler .chat_info ):
32+ tool_id = None
33+ knowledge_id = None
34+ if [WorkflowMode .KNOWLEDGE , WorkflowMode .KNOWLEDGE_LOOP ].__contains__ (self .workflow_manage .flow .workflow_mode ):
35+ knowledge_id = self .workflow_params .get ('knowledge_id' )
36+ elif [WorkflowMode .APPLICATION , WorkflowMode .APPLICATION_LOOP ].__contains__ (
37+ self .workflow_manage .flow .workflow_mode ):
3438 application_id = self .workflow_manage .work_flow_post_handler .chat_info .application .id
35- knowledge_id = self .workflow_params .get ('knowledge_id' )
39+ elif [WorkflowMode .TOOL , WorkflowMode .TOOL_LOOP ].__contains__ (self .workflow_manage .flow .workflow_mode ):
40+ tool_id = self .workflow_params .get ('tool_id' )
3641
3742 # doc文件中的图片保存
3843 def save_image (image_list ):
3944 for image in image_list :
4045 meta = {
41- 'debug' : False if (application_id or knowledge_id ) else True ,
46+ 'debug' : False if (application_id or knowledge_id or tool_id ) else True ,
4247 'chat_id' : chat_id ,
4348 'application_id' : str (application_id ) if application_id else None ,
4449 'knowledge_id' : str (knowledge_id ) if knowledge_id else None ,
50+ 'tool_id' : str (tool_id ) if tool_id else None ,
4551 'file_id' : str (image .id )
4652 }
4753 file_bytes = image .meta .pop ('content' )
4854 new_file = File (
4955 id = meta ['file_id' ],
5056 file_name = image .file_name ,
5157 file_size = len (file_bytes ),
52- source_type = FileSourceType .APPLICATION .value if meta [
53- 'application_id' ] else FileSourceType .KNOWLEDGE .value ,
54- source_id = meta ['application_id' ] if meta ['application_id' ] else meta ['knowledge_id' ],
58+ source_type = FileSourceType .APPLICATION .value if application_id else FileSourceType .KNOWLEDGE .value if knowledge_id else FileSourceType .APPLICATION .value ,
59+ source_id = application_id or tool_id or knowledge_id ,
5560 meta = meta
5661 )
5762 if not QuerySet (File ).filter (id = new_file .id ).exists ():
0 commit comments