MCPcopy Create free account
hub / github.com/Louisym/MiniCC / from_dict

Method from_dict

tutorials/12_session_persistence.py:115–135  ·  view source on GitHub ↗

从字典反序列化

(data: dict)

Source from the content-addressed store, hash-verified

113
114 @staticmethod
115 def from_dict(data: dict) -> "ContentBlock":
116 """从字典反序列化"""
117 block_type = data["type"]
118 if block_type == "text":
119 return ContentBlock(block_type="text", text=data["text"])
120 elif block_type == "tool_use":
121 return ContentBlock(
122 block_type="tool_use",
123 tool_id=data["id"],
124 tool_name=data["name"],
125 tool_input=data["input"],
126 )
127 elif block_type == "tool_result":
128 return ContentBlock(
129 block_type="tool_result",
130 tool_use_id=data["tool_use_id"],
131 tool_name=data["tool_name"],
132 output=data["output"],
133 is_error=data.get("is_error", False),
134 )
135 raise ValueError(f"unknown block type: {block_type}")
136
137
138@dataclass

Callers 3

from_dictMethod · 0.45
load_session_jsonFunction · 0.45
load_sessionMethod · 0.45

Calls 2

ContentBlockClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected