序列化为字典(用于 JSON)
(self)
| 91 | is_error: bool = False |
| 92 | |
| 93 | def to_dict(self) -> dict: |
| 94 | """序列化为字典(用于 JSON)""" |
| 95 | if self.block_type == "text": |
| 96 | return {"type": "text", "text": self.text} |
| 97 | elif self.block_type == "tool_use": |
| 98 | return { |
| 99 | "type": "tool_use", |
| 100 | "id": self.tool_id, |
| 101 | "name": self.tool_name, |
| 102 | "input": self.tool_input, |
| 103 | } |
| 104 | elif self.block_type == "tool_result": |
| 105 | return { |
| 106 | "type": "tool_result", |
| 107 | "tool_use_id": self.tool_use_id, |
| 108 | "tool_name": self.tool_name, |
| 109 | "output": self.output, |
| 110 | "is_error": self.is_error, |
| 111 | } |
| 112 | return {} |
| 113 | |
| 114 | @staticmethod |
| 115 | def from_dict(data: dict) -> "ContentBlock": |
no outgoing calls
no test coverage detected