Spaces:
Sleeping
Sleeping
fix(backend): add session auto_title from first user message
Browse files- app/api/chat.py +7 -1
app/api/chat.py
CHANGED
|
@@ -168,7 +168,13 @@ async def _run_agent(
|
|
| 168 |
state["messages"] = history_msgs
|
| 169 |
|
| 170 |
# 4. 记录 user message 到 SQLite
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
db.message_insert({
|
| 173 |
"id": uuid.uuid4().hex,
|
| 174 |
"session_id": req.session_id,
|
|
|
|
| 168 |
state["messages"] = history_msgs
|
| 169 |
|
| 170 |
# 4. 记录 user message 到 SQLite
|
| 171 |
+
# - 若 session 还没有 title 且这是首条 user 消息, 自动从前 30 字生成
|
| 172 |
+
existing = db.session_get(req.session_id)
|
| 173 |
+
auto_title = None
|
| 174 |
+
if existing is None or not existing.get("title"):
|
| 175 |
+
from app.api.sessions import _auto_title
|
| 176 |
+
auto_title = _auto_title(req.message)
|
| 177 |
+
db.session_upsert(req.session_id, title=auto_title)
|
| 178 |
db.message_insert({
|
| 179 |
"id": uuid.uuid4().hex,
|
| 180 |
"session_id": req.session_id,
|