Spaces:
Sleeping
Sleeping
Commit
·
2534de8
1
Parent(s):
40d8682
fix: Chat name generation now only happens once per session
Browse files- Added check before calling chat name generation
- Prevents multiple Bedrock API calls for same session
- Fixes 'Failed to generate chat name' spam in logs
- Chat name generates only after first user message if not already set
- services/session_manager.py +10 -2
services/session_manager.py
CHANGED
|
@@ -154,9 +154,17 @@ class SessionManager:
|
|
| 154 |
}
|
| 155 |
)
|
| 156 |
|
| 157 |
-
|
|
|
|
| 158 |
if role == "user" and not content.lower().startswith("uploaded file"):
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
return schema_to_dict(message_record)
|
| 162 |
|
|
|
|
| 154 |
}
|
| 155 |
)
|
| 156 |
|
| 157 |
+
|
| 158 |
+
# Auto-generate chat name after first user message (only if not already generated)
|
| 159 |
if role == "user" and not content.lower().startswith("uploaded file"):
|
| 160 |
+
# Check if chat name already exists to avoid unnecessary generation attempts
|
| 161 |
+
session = self.sessions_collection.find_one(
|
| 162 |
+
{"session_id": session_id},
|
| 163 |
+
{"chat_name": 1, "_id": 0}
|
| 164 |
+
)
|
| 165 |
+
if session and not session.get("chat_name"):
|
| 166 |
+
self._maybe_generate_chat_name(session_id)
|
| 167 |
+
|
| 168 |
|
| 169 |
return schema_to_dict(message_record)
|
| 170 |
|