From b04242bbb26468ca45ce18c193ee13042aca03b1 Mon Sep 17 00:00:00 2001 From: Cxx0822 <1556464090@qq.com> Date: Sun, 31 May 2026 21:20:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8E=86=E5=8F=B2=E6=B6=88=E6=81=AF=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chief.db-shm | Bin 0 -> 32768 bytes chief.db-wal | 0 model.py | 5 +++++ router.py | 19 +++++++++++++------ services/agent_service.py | 9 ++++++++- services/db_service.py | 31 +++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 chief.db-shm create mode 100644 chief.db-wal diff --git a/chief.db-shm b/chief.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10 GIT binary patch literal 32768 zcmeIuAr62r3 list[dict[str, str]]: result.append({"role": "ai", "content": msg.content}) return result + + +# 查询历史会话消息 +def get_user_session_messages(username: str): + """查询历史会话消息""" + print(f"查询历史会话消息,username: {username}") + return query_session_messages(username) diff --git a/services/db_service.py b/services/db_service.py index 9accfbd..e6497a6 100644 --- a/services/db_service.py +++ b/services/db_service.py @@ -1,5 +1,8 @@ import sqlite3 import os +from typing import List + +from model import SessionMessageResponse def init_db(): @@ -20,6 +23,34 @@ def init_db(): conn.close() +def query_session_messages(username: str) -> List[SessionMessageResponse]: + conn = sqlite3.connect(os.getenv("SQLITE_DB_PATH")) + conn.row_factory = sqlite3.Row + cursor = conn.cursor() + + cursor.execute( + """ + SELECT username, title, thread_id + FROM session + WHERE username = ? + ORDER BY created_time DESC + """, + (username,) + ) + + rows = cursor.fetchall() + conn.close() + + return [ + SessionMessageResponse( + username=row["username"], + title=row["title"], + thread_id=row["thread_id"], + ) + for row in rows + ] + + def exists_session(thread_id: str, username: str) -> bool: conn = sqlite3.connect(os.getenv("SQLITE_DB_PATH")) cursor = conn.cursor()