更新
This commit is contained in:
@@ -102,8 +102,14 @@ class ConversationStore:
|
||||
user_text: str,
|
||||
assistant_text: str,
|
||||
exchange_id: str,
|
||||
user_image: str = "",
|
||||
) -> bool:
|
||||
"""Atomically append one user/assistant pair once across crash recovery."""
|
||||
"""Atomically append one user/assistant pair once across crash recovery.
|
||||
|
||||
`user_image` 是 media/ 目录下的文件名(不是绝对路径),只在客户发来图片、
|
||||
表情这类没有可复制文本的消息时才有值。存文件名而不是路径,档案换台机器
|
||||
打开也还能对上。
|
||||
"""
|
||||
key = str(fp_hex or "")
|
||||
txid = str(exchange_id or "")
|
||||
if not key or not txid:
|
||||
@@ -119,8 +125,16 @@ class ConversationStore:
|
||||
committed = entry.setdefault("exchange_ids", [])
|
||||
if txid not in committed:
|
||||
now = time.time()
|
||||
user_message = {
|
||||
"role": "user",
|
||||
"content": str(user_text or ""),
|
||||
"ts": now,
|
||||
}
|
||||
# 只有存下画面时才写这个键:老档案里没有它,读取方一律按缺省处理
|
||||
if str(user_image or "").strip():
|
||||
user_message["image"] = str(user_image).strip()
|
||||
entry["history"].extend([
|
||||
{"role": "user", "content": str(user_text or ""), "ts": now},
|
||||
user_message,
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": str(assistant_text or ""),
|
||||
|
||||
Reference in New Issue
Block a user