From d4bcb8174e2be96cf05f241a80a81e76578637ea Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 26 Mar 2025 13:41:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8F=AF=E8=83=BD=E5=BD=A2=E6=88=90=20SQL=20?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E7=9A=84=E9=A3=8E=E9=99=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/db/sqlite.py | 33 +++++++++---------- astrbot/core/db/sqlite_init.sql | 8 +++-- .../process_stage/method/llm_request.py | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/astrbot/core/db/sqlite.py b/astrbot/core/db/sqlite.py index 98e6af04e..65d68526e 100644 --- a/astrbot/core/db/sqlite.py +++ b/astrbot/core/db/sqlite.py @@ -128,24 +128,23 @@ class SQLiteDatabase(BaseDatabase): except sqlite3.ProgrammingError: c = self._get_conn(self.db_path).cursor() - where_clause = "" - if session_id or provider_type: - where_clause += " WHERE " - has = False - if session_id: - where_clause += f"session_id = '{session_id}'" - has = True - if provider_type: - if has: - where_clause += " AND " - where_clause += f"provider_type = '{provider_type}'" + conditions = [] + params = [] + + if session_id: + conditions.append("session_id = ?") + params.append(session_id) + + if provider_type: + conditions.append("provider_type = ?") + params.append(provider_type) + + sql = "SELECT * FROM llm_history" + if conditions: + sql += " WHERE " + " AND ".join(conditions) + + c.execute(sql, params) - c.execute( - """ - SELECT * FROM llm_history - """ - + where_clause - ) res = c.fetchall() histories = [] for row in res: diff --git a/astrbot/core/db/sqlite_init.sql b/astrbot/core/db/sqlite_init.sql index 900f4f2c0..a1ebc54b5 100644 --- a/astrbot/core/db/sqlite_init.sql +++ b/astrbot/core/db/sqlite_init.sql @@ -38,11 +38,13 @@ CREATE TABLE IF NOT EXISTS atri_vision( ); CREATE TABLE IF NOT EXISTS webchat_conversation( - user_id TEXT, - cid TEXT, + user_id TEXT, -- 会话 id + cid TEXT, -- 对话 id history TEXT, created_at INTEGER, updated_at INTEGER, title TEXT, persona_id TEXT -); \ No newline at end of file +); + +PRAGMA encoding = 'UTF-8'; \ No newline at end of file diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index 872875e8f..8d606d9e5 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -128,7 +128,7 @@ class LLMRequestSubStage(Stage): # max context length if ( - self.max_context_length != -1 # -1 为不限制 + self.max_context_length != -1 # -1 为不限制 and len(req.contexts) // 2 > self.max_context_length ): logger.debug("上下文长度超过限制,将截断。")