Each assistant message in the session JSON now carries: backend, backend_label, host (platform.node()) These fields are shown as model tags in the UI — on live responses and when loading session history. Session log entries (sessions/YYYY-MM-DD.md) include the backend label and host in the turn header. The local (OpenAI-compat) backend strips non-standard fields before sending messages to the API so extra fields don't leak upstream. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
924 B
Python
32 lines
924 B
Python
from datetime import datetime
|
|
from config import settings
|
|
from persona import persona_path
|
|
|
|
|
|
def log_turn(
|
|
session_id: str,
|
|
user_msg: str,
|
|
assistant_msg: str,
|
|
backend_label: str = "",
|
|
host: str = "",
|
|
) -> None:
|
|
today = datetime.now().strftime("%Y-%m-%d")
|
|
sessions_dir = persona_path() / "sessions"
|
|
sessions_dir.mkdir(exist_ok=True)
|
|
|
|
log_file = sessions_dir / f"{today}.md"
|
|
timestamp = datetime.now().strftime("%H:%M")
|
|
is_new = not log_file.exists()
|
|
|
|
meta_parts = [p for p in [backend_label, host] if p]
|
|
meta = f" · {' / '.join(meta_parts)}" if meta_parts else ""
|
|
|
|
with open(log_file, "a") as f:
|
|
if is_new:
|
|
f.write(f"# Session Log — {today}\n")
|
|
f.write(
|
|
f"\n### [{timestamp}] `{session_id}`{meta}\n"
|
|
f"**{settings.user_name}:** {user_msg}\n\n"
|
|
f"**{settings.agent_name}:** {assistant_msg}\n"
|
|
)
|