Paulhayes commited on
Commit
8a338bb
·
verified ·
1 Parent(s): d75e4ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -363,6 +363,18 @@ def _atomic_write_json(path, data):
363
  json.dump(data, f, ensure_ascii=False, indent=2)
364
  os.replace(tmp, path)
365
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  class KnowledgeStore:
367
  def __init__(self, storage_path: str):
368
  self.base = _Path(storage_path)
 
363
  json.dump(data, f, ensure_ascii=False, indent=2)
364
  os.replace(tmp, path)
365
 
366
+ def _load_json(path, default):
367
+ if os.path.exists(path):
368
+ try:
369
+ with open(path, "r", encoding="utf-8") as f:
370
+ return json.load(f)
371
+ except (json.JSONDecodeError, IOError):
372
+ return default
373
+ return default
374
+
375
+ def _save_json(path, data):
376
+ _atomic_write_json(path, data)
377
+
378
  class KnowledgeStore:
379
  def __init__(self, storage_path: str):
380
  self.base = _Path(storage_path)