Files
opro_demo/session_state.py

27 lines
616 B
Python
Raw Permalink Normal View History

2025-12-05 07:11:25 +00:00
import uuid
SESSIONS = {}
def create_session(query: str) -> str:
sid = uuid.uuid4().hex
SESSIONS[sid] = {
"original_query": query,
"round": 0,
"history_candidates": [],
"user_feedback": []
}
return sid
def get_session(sid: str):
return SESSIONS.get(sid)
def update_session_add_candidates(sid: str, candidates: list):
s = SESSIONS[sid]
s["round"] += 1
s["history_candidates"].extend(candidates)
def log_user_choice(sid: str, choice: str):
SESSIONS[sid]["user_feedback"].append(
{"round": SESSIONS[sid]["round"], "choice": choice}
)