baya1116's picture
Super-squash branch 'main' using huggingface_hub
b5989f0
Raw
History Blame Contribute Delete
1.77 kB
import sys, os, time
sys.path.insert(0, os.getcwd())
import tiered_rag_mlx as T
P="/tmp/app_session_mem.jsonl"
if os.path.exists(P): os.remove(P)
chat = T.ChatSession(T.TieredMemory(P)) # rw=1024, temp 0.6
def on_message(text):
intent = T.classify(text)
if intent == "fact":
ans,_,_ = chat.turn(text, store="session", ack_only=True) # instant ack, logged
return intent, "stored", ans
mathish = intent in ("math","command")
msg = text + (" Please reason step by step and give the final number." if mathish else "")
ans, src, _ = chat.turn(msg, store="none")
return intent, (src or "—"), ans
turns = [
("hey, I'm planning a weekend trip", None),
("I'm going to Kyoto for 3 days", None),
("my budget is $800", None),
("if I spend $120 a day for 3 days, what's the total food cost?", ("math","360")),
("actually make it 4 days instead", None),
("recompute the food total", ("command","480")),
("who is the current emperor of Japan?", ("question","Naruhito")),
("explain what a ryokan is", ("chitchat",None)),
("remind me how long I'm staying and my budget", ("question","4 days / 800")),
("I'm vegetarian", None),
("what dietary preference should I mention at restaurants?", ("question","vegetarian")),
("thanks, that's all!", None),
]
print("# Realistic app session — full pipeline\n", flush=True)
for u, chk in turns:
t0=time.time(); intent, path, ans = on_message(u); dt=time.time()-t0
print("="*70, flush=True)
print(f"USER: {u}", flush=True)
print(f" [intent={intent} · {path} · {dt:.0f}s]", flush=True)
print(f"ASSISTANT: {ans[:240]}", flush=True)
if chk: print(f" >>> expect {chk[0]}" + (f" ~ '{chk[1]}'" if chk[1] else ""), flush=True)
print("\nAPP_SESSION_DONE", flush=True)