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

Function load_session_json

tutorials/12_session_persistence.py:256–274  ·  view source on GitHub ↗

从 JSON 文件加载会话。 对应源码: session.rs:93-96 pub fn load_from_path(path) -> Result { let contents = fs::read_to_string(path)?; Self::from_json(&JsonValue::parse(&contents)?) }

(path: str)

Source from the content-addressed store, hash-verified

254
255
256def load_session_json(path: str) -> Session:
257 """
258 从 JSON 文件加载会话。
259
260 对应源码: session.rs:93-96
261 pub fn load_from_path(path) -> Result<Self, SessionError> {
262 let contents = fs::read_to_string(path)?;
263 Self::from_json(&JsonValue::parse(&contents)?)
264 }
265 """
266 with open(path, "r") as f:
267 data = json.load(f)
268 session = Session(
269 version=data["version"],
270 session_id=data.get("session_id", ""),
271 )
272 for msg_data in data["messages"]:
273 session.messages.append(ConversationMessage.from_dict(msg_data))
274 return session
275
276
277# --- 方案 B:JSONL 仅追加 ---

Callers 1

mainFunction · 0.85

Calls 5

appendMethod · 0.80
SessionClass · 0.70
loadMethod · 0.45
getMethod · 0.45
from_dictMethod · 0.45

Tested by

no test coverage detected