feat: store and display backend + host metadata on chat messages
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>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import json
|
||||
import platform
|
||||
import jwt
|
||||
from fastapi import APIRouter, HTTPException, Query, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
@@ -108,10 +109,18 @@ async def _stream_chat(req: ChatRequest):
|
||||
|
||||
try:
|
||||
response_text, actual_backend = task.result()
|
||||
history.append({"role": "assistant", "content": response_text})
|
||||
backend_label = _backend_label(actual_backend, user, role="chat")
|
||||
host = platform.node()
|
||||
history.append({
|
||||
"role": "assistant",
|
||||
"content": response_text,
|
||||
"backend": actual_backend,
|
||||
"backend_label": backend_label,
|
||||
"host": host,
|
||||
})
|
||||
save_session(session_id, history)
|
||||
if not req.off_record:
|
||||
log_turn(session_id, req.message, response_text)
|
||||
log_turn(session_id, req.message, response_text, backend_label, host)
|
||||
|
||||
# fallback_used only makes sense for explicit backend selections.
|
||||
# In auto mode (req.model is None), just report what responded.
|
||||
@@ -121,7 +130,8 @@ async def _stream_chat(req: ChatRequest):
|
||||
"response": response_text,
|
||||
"session_id": session_id,
|
||||
"backend": actual_backend,
|
||||
"backend_label": _backend_label(actual_backend, user, role="chat"),
|
||||
"backend_label": backend_label,
|
||||
"host": host,
|
||||
"fallback_used": fallback_used,
|
||||
}
|
||||
yield f"data: {json.dumps(payload)}\n\n"
|
||||
|
||||
Reference in New Issue
Block a user