File size: 1,817 Bytes
83adb51 d71458e 83adb51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #!/usr/bin/env python3
"""Clear specific cache entries so they get regenerated with the new adaptive radius."""
import json, os, sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from dotenv import load_dotenv
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), "..", ".env"), override=True)
CACHE_FILE = os.path.join(os.path.dirname(__file__), "..", ".cache", "llm_cache.json")
WARMUP_PROGRESS = os.path.join(os.path.dirname(__file__), "..", ".warmup_progress.json")
CATS = ["Landmark", "Culture", "Nature", "Gems", "Photo", "Food", "Shopping"]
def cat_hash(name):
d = {c: (c == name) for c in CATS}
return json.dumps(d, sort_keys=True)
# Cities to fully clear (all categories)
FULL_CLEAR = ["Bali", "Dubai"]
# Specific combos to clear
COMBO_CLEAR = [
("Marrakech", "Landmark"),
("Kyoto", "Shopping"),
]
with open(CACHE_FILE) as f:
cache = json.load(f)
removed = 0
# Full clear
for city in FULL_CLEAR:
for cat in CATS:
key = json.dumps([city, cat_hash(cat)])
if key in cache:
del cache[key]
removed += 1
# Specific combos
for city, cat in COMBO_CLEAR:
key = json.dumps([city, cat_hash(cat)])
if key in cache:
del cache[key]
removed += 1
with open(CACHE_FILE, "w") as f:
json.dump(cache, f)
# Also clear warmup progress for these so the warmup retries them
with open(WARMUP_PROGRESS) as f:
progress = json.load(f)
for cid in list(progress["combos"].keys()):
city, cat = cid.split("::")
if city in FULL_CLEAR:
del progress["combos"][cid]
elif (city, cat) in COMBO_CLEAR:
del progress["combos"][cid]
with open(WARMUP_PROGRESS, "w") as f:
json.dump(progress, f, indent=2)
print(f"Cleared {removed} cache entries + progress for re-warmup")
|