persist perplexity per assistant message; display on loaded convos

This commit is contained in:
gramps
2026-07-14 14:13:24 -07:00
parent 65baeba1f1
commit 7d50d07249
5 changed files with 37 additions and 21 deletions
+6 -6
View File
@@ -132,8 +132,8 @@ async def chat_completions(request: Request):
content = msg.get("content", "")
if role in ("user", "assistant"):
db.execute(
"INSERT INTO messages (conversation_id, role, content, created_at) VALUES (?, ?, ?, ?)",
(conv_id, role, encrypt_text(content), now),
"INSERT INTO messages (conversation_id, role, content, created_at, perplexity) VALUES (?, ?, ?, ?, ?)",
(conv_id, role, encrypt_text(content), now, None),
)
db.commit()
@@ -195,8 +195,8 @@ async def _stream_chat(payload: dict, model: str, conv_id: str, request: Request
if assistant_msg:
db = get_db()
db.execute(
"INSERT INTO messages (conversation_id, role, content, created_at) VALUES (?, ?, ?, ?)",
(conv_id, "assistant", encrypt_text(assistant_msg), datetime.now(timezone.utc).isoformat()),
"INSERT INTO messages (conversation_id, role, content, created_at, perplexity) VALUES (?, ?, ?, ?, ?)",
(conv_id, "assistant", encrypt_text(assistant_msg), datetime.now(timezone.utc).isoformat(), None),
)
db.commit()
db.close()
@@ -240,8 +240,8 @@ async def _blocking_chat(payload: dict, model: str, conv_id: str, request: Reque
if assistant_msg:
db = get_db()
db.execute(
"INSERT INTO messages (conversation_id, role, content, created_at) VALUES (?, ?, ?, ?)",
(conv_id, "assistant", encrypt_text(assistant_msg), datetime.now(timezone.utc).isoformat()),
"INSERT INTO messages (conversation_id, role, content, created_at, perplexity) VALUES (?, ?, ?, ?, ?)",
(conv_id, "assistant", encrypt_text(assistant_msg), datetime.now(timezone.utc).isoformat(), None),
)
db.commit()
db.close()