fixed reasoning
This commit is contained in:
@@ -37,6 +37,18 @@ MAX_HISTORY_MESSAGES = 40
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _build_messages_for_session(session_id: int) -> list[dict[str, Any]]:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
service = ChatService(db)
|
||||
session = service.get_session(session_id)
|
||||
if not session:
|
||||
return []
|
||||
return service._build_messages(session)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
async def _extract_memory_background(
|
||||
session_id: int,
|
||||
user_text: str,
|
||||
@@ -166,7 +178,12 @@ class ChatService:
|
||||
return
|
||||
|
||||
self._save_message(session_id, "user", user_text)
|
||||
messages = self._build_messages(session)
|
||||
yield self._sse("status", {"phase": "preparing"})
|
||||
messages = await asyncio.to_thread(_build_messages_for_session, session_id)
|
||||
if not messages:
|
||||
yield self._sse("error", {"message": "Session not found"})
|
||||
return
|
||||
yield self._sse("status", {"phase": "generating"})
|
||||
streamed_reply_parts: list[str] = []
|
||||
|
||||
for _ in range(MAX_TOOL_ROUNDS):
|
||||
|
||||
Reference in New Issue
Block a user