从 JSON 文件加载(读档)
(cls, path: str)
| 248 | |
| 249 | @classmethod |
| 250 | def load_from_file(cls, path: str) -> "Session": |
| 251 | """从 JSON 文件加载(读档)""" |
| 252 | with open(path, "r", encoding="utf-8") as f: |
| 253 | data = json.load(f) |
| 254 | session = cls(version=data["version"]) |
| 255 | for msg_data in data["messages"]: |
| 256 | session.messages.append(cls._dict_to_message(msg_data)) |
| 257 | return session |
| 258 | |
| 259 | @staticmethod |
| 260 | def _message_to_dict(msg: ConversationMessage) -> dict: |
no test coverage detected