File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22import asyncio
3+ import base64
34import io
45import json
56import os
@@ -613,6 +614,11 @@ def export(self):
613614 id = self .data .get ('id' )
614615 tool = QuerySet (Tool ).filter (id = id ).first ()
615616 tool_dict = ToolExportModelSerializer (tool ).data
617+ # 如果是SKILL类型的工具,校验文件是否存在
618+ if tool .tool_type == ToolType .SKILL :
619+ skill_file = QuerySet (File ).filter (id = tool .code ).first ()
620+ if skill_file :
621+ tool_dict ['code' ] = base64 .b64encode (skill_file .get_bytes ()).decode ('utf-8' )
616622 mk_instance = ToolInstance (tool_dict , 'v2' )
617623 tool_pickle = pickle .dumps (mk_instance )
618624 response = HttpResponse (content_type = 'text/plain' , content = tool_pickle )
@@ -662,11 +668,23 @@ def import_(self, scope=ToolScope.WORKSPACE):
662668 folder_id = self .data .get ('folder_id' )
663669 tool = tool_instance .tool
664670 tool_id = uuid .uuid7 ()
671+ code = tool .get ('code' )
672+ if tool .get ('tool_type' ) == ToolType .SKILL :
673+ skill_file_id = uuid .uuid7 ()
674+ skill_file = File (
675+ id = skill_file_id ,
676+ file_name = f"{ tool .get ('name' )} .zip" ,
677+ source_type = FileSourceType .TOOL ,
678+ source_id = tool_id ,
679+ meta = {}
680+ )
681+ skill_file .save (base64 .b64decode (code ))
682+ code = skill_file_id
665683 tool_model = Tool (
666684 id = tool_id ,
667685 name = tool .get ('name' ),
668686 desc = tool .get ('desc' ),
669- code = tool . get ( ' code' ) ,
687+ code = code ,
670688 user_id = user_id ,
671689 workspace_id = self .data .get ('workspace_id' ),
672690 input_field_list = tool .get ('input_field_list' ),
You can’t perform that action at this time.
0 commit comments