MCPcopy
hub / github.com/1Panel-dev/MaxKB / to_tool

Method to_tool

apps/application/serializers/application.py:746–779  ·  view source on GitHub ↗

@param workspace_id: @param user_id: 用户id @param tool: 工具 @return:

(tool, workspace_id, user_id)

Source from the content-addressed store, hash-verified

744
745 @staticmethod
746 def to_tool(tool, workspace_id, user_id):
747 """
748 @param workspace_id:
749 @param user_id: 用户id
750 @param tool: 工具
751 @return:
752 """
753 # 如果是技能类型的工具,需要将code保存为文件
754 code = tool.get("code")
755 if tool.get("tool_type") == ToolType.SKILL:
756 skill_file_id = uuid.uuid7()
757 skill_file = File(
758 id=skill_file_id,
759 file_name=f"{tool.get('name')}.zip",
760 source_type=FileSourceType.TOOL,
761 source_id=tool.get("id"),
762 meta={},
763 )
764 skill_file.save(base64.b64decode(code))
765 tool["code"] = skill_file_id
766 return Tool(
767 id=tool.get("id"),
768 user_id=user_id,
769 name=tool.get("name"),
770 code=tool.get("code"),
771 template_id=tool.get("template_id"),
772 input_field_list=tool.get("input_field_list"),
773 init_field_list=tool.get("init_field_list"),
774 is_active=False if len((tool.get("init_field_list") or [])) > 0 else tool.get("is_active"),
775 tool_type=tool.get("tool_type", "CUSTOM") or "CUSTOM",
776 scope=ToolScope.WORKSPACE,
777 folder_id=workspace_id,
778 workspace_id=workspace_id,
779 )
780
781 @staticmethod
782 def reset_workflow(work_flow, update_tool_map):

Callers 1

import_Method · 0.95

Calls 4

saveMethod · 0.95
FileClass · 0.90
ToolClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected