appQQQ commited on
Commit
bf67d84
·
verified ·
1 Parent(s): f6d6051

fix: restore colbert/ + persist after chat

Browse files
Files changed (1) hide show
  1. app/api/chat.py +9 -0
app/api/chat.py CHANGED
@@ -31,6 +31,7 @@ from app.llm.base import LLMMessage
31
  from app.llm.factory import get_llm
32
  from app.models import db
33
  from app.models.schemas import ChatRequest, ChatResponse
 
34
  from app.streaming.events import (
35
  sse_done,
36
  sse_error,
@@ -244,4 +245,12 @@ async def _run_agent(
244
  "citations": final_state.get("citations", []),
245
  })
246
 
 
 
 
 
 
 
 
 
247
  return final_state, events_log
 
31
  from app.llm.factory import get_llm
32
  from app.models import db
33
  from app.models.schemas import ChatRequest, ChatResponse
34
+ from app.services.persist import schedule_push
35
  from app.streaming.events import (
36
  sse_done,
37
  sse_error,
 
245
  "citations": final_state.get("citations", []),
246
  })
247
 
248
+ # 9. ⚠️ 关键: 把 session/message 写完 → 调度 persist push (5s debounce).
249
+ # 不调的话: 写本地 /data/sqlite/app.db → Space 重启 /data 临时卷清空 →
250
+ # 历史对话全丢. 5s debounce 够合并同一 session 的 user+assistant 写入.
251
+ try:
252
+ await schedule_push()
253
+ except Exception as e: # noqa: BLE001
254
+ logger.warning("schedule_push after chat failed: %s", e)
255
+
256
  return final_state, events_log