BreadBuddy / history.py
CEO的小跟班
fix: downgrade Gradio to 5.50.0, fix app_file path
3933b9c
Raw
History Blame Contribute Delete
681 Bytes
"""
deploy/history.py — 单会话对话历史管理
简化版:只维护一个 diagnosis 会话(不再有 per-tab 历史)。
"""
MAX_HISTORY_TURNS = 10
_history: list[dict] = []
def get_history() -> list[dict]:
"""Get conversation history, truncated to MAX_HISTORY_TURNS."""
if len(_history) > MAX_HISTORY_TURNS * 2:
return _history[-(MAX_HISTORY_TURNS * 2):]
return list(_history)
def append_to_history(user_msg: dict, assistant_msg: dict):
"""Append a turn (user + assistant) to history."""
_history.append(user_msg)
_history.append(assistant_msg)
def clear_history():
"""Clear all conversation history."""
_history.clear()