MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / export

Method export

apps/tools/serializers/tool.py:807–829  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

805 return response
806
807 def export(self):
808 try:
809 self.is_valid()
810 id = self.data.get("id")
811 tool = QuerySet(Tool).filter(id=id).first()
812 tool_dict = ToolExportModelSerializer(tool).data
813 # 如果是SKILL类型的工具,校验文件是否存在
814 if tool.tool_type == ToolType.SKILL:
815 skill_file = QuerySet(File).filter(id=tool.code).first()
816 if skill_file:
817 tool_dict["code"] = base64.b64encode(skill_file.get_bytes()).decode("utf-8")
818 if tool.tool_type == ToolType.WORKFLOW:
819 workflow = QuerySet(ToolWorkflow).filter(tool_id=tool.id).first()
820 if workflow:
821 tool_dict["work_flow"] = workflow.work_flow
822 tool_dict["tool_list"] = self.get_child_tool_list(workflow.work_flow, [])
823 mk_instance = ToolInstance(tool_dict, "v2")
824 tool_pickle = pickle.dumps(mk_instance)
825 response = HttpResponse(content_type="text/plain", content=tool_pickle)
826 response["Content-Disposition"] = f'attachment; filename="{tool.name}.tool"'
827 return response
828 except Exception as e:
829 return result.error(str(e), response_status=status.HTTP_500_INTERNAL_SERVER_ERROR)
830
831 class Pylint(serializers.Serializer):
832 def run(self, instance, is_valid=True):

Callers 5

getMethod · 0.45
speech_to_textMethod · 0.45
any_to_amrFunction · 0.45
any_to_mp3Function · 0.45
split_and_transcribeFunction · 0.45

Calls 8

is_validMethod · 0.95
get_child_tool_listMethod · 0.95
ToolInstanceClass · 0.85
decodeMethod · 0.80
get_bytesMethod · 0.80
getMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected