原始代码
This commit is contained in:
26
session_state.py
Normal file
26
session_state.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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}
|
||||
)
|
||||
Reference in New Issue
Block a user