File size: 1,980 Bytes
2a79143 | 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 63 | import sys
sys.path.insert(0, ".")
from src.state import ResearchState, Paper, Claim, Verdict, SessionContext
from src.memory import init_db, load_session, save_turn, export_session_md, delete_session
from src.state import SessionUpdate
import uuid
print("=== Phase 2: State + Memory ===")
# Test 1: State dataclasses
p = Paper(
title="Test Paper",
abstract="This is a test abstract.",
year=2024,
citation_count=100,
paper_id="abc123"
)
print(f"β Paper dataclass: {p.title} ({p.year})")
c = Claim(text="Test claim", source_title="Test Paper", source_year=2024, confidence="high")
print(f"β Claim dataclass: [{c.confidence}] {c.text}")
print(f"β Verdict constants: {Verdict.PASS} / {Verdict.STALE} / {Verdict.CONTRADICTED}")
# Test 2: SQLite memory
init_db()
print("β Database initialized")
session_id = str(uuid.uuid4())
# Load empty session
ctx = load_session(session_id)
print(f"β Empty session loaded: {len(ctx.prior_positions)} prior positions")
# Save a turn
update = SessionUpdate(
query="What is the state of KV cache compression?",
position="KV cache compression has advanced significantly with methods like H2O and StreamingLLM.",
claim_confidences=[
Claim("H2O reduces KV cache size by 20x", "H2O Paper", 2023, "high"),
Claim("StreamingLLM enables infinite context", "StreamingLLM", 2023, "medium"),
],
contradictions_found=["StreamingLLM contradicted by later infinite attention work (2024)"]
)
save_turn(session_id, update)
print("β Turn saved to database")
# Reload and verify
ctx2 = load_session(session_id)
print(f"β Session reloaded: {len(ctx2.prior_positions)} prior position(s)")
print(f" Prior query: {ctx2.prior_queries[0][:60]}...")
# Export markdown
md = export_session_md(session_id)
print(f"β Markdown export: {len(md)} characters")
print(f" Preview: {md[:120].strip()}")
# Cleanup
delete_session(session_id)
print("β Session deleted")
print("\nβ
Phase 2 complete") |