@@ -17,19 +17,6 @@ def __init__(
17
17
self .create ()
18
18
19
19
def create (self ):
20
- # answer_table_sql = """CREATE TABLE IF NOT EXISTS `modelcache_llm_answer` (
21
- # `id` bigint(20) NOT NULL AUTO_INCREMENT comment '主键',
22
- # `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
23
- # `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
24
- # `question` text NOT NULL comment 'question',
25
- # `answer` text NOT NULL comment 'answer',
26
- # `answer_type` int(11) NOT NULL comment 'answer_type',
27
- # `hit_count` int(11) NOT NULL DEFAULT '0' comment 'hit_count',
28
- # `model` varchar(1000) NOT NULL comment 'model',
29
- # `embedding_data` blob NOT NULL comment 'embedding_data',
30
- # PRIMARY KEY(`id`)
31
- # ) AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT = 'modelcache_llm_answer';
32
- # """
33
20
answer_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_llm_answer (
34
21
id INTEGER PRIMARY KEY AUTOINCREMENT,
35
22
gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -43,21 +30,6 @@ def create(self):
43
30
);
44
31
"""
45
32
46
- # log_table_sql = """CREATE TABLE IF NOT EXISTS `modelcache_query_log` (
47
- # `id` bigint(20) NOT NULL AUTO_INCREMENT comment '主键',
48
- # `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
49
- # `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
50
- # `error_code` int(11) NOT NULL comment 'errorCode',
51
- # `error_desc` varchar(1000) NOT NULL comment 'errorDesc',
52
- # `cache_hit` varchar(100) NOT NULL comment 'cacheHit',
53
- # `delta_time` float NOT NULL comment 'delta_time',
54
- # `model` varchar(1000) NOT NULL comment 'model',
55
- # `query` text NOT NULL comment 'query',
56
- # `hit_query` text NOT NULL comment 'hitQuery',
57
- # `answer` text NOT NULL comment 'answer',
58
- # PRIMARY KEY(`id`)
59
- # ) AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT = 'modelcache_query_log';
60
- # """
61
33
log_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_query_log (
62
34
id INTEGER PRIMARY KEY AUTOINCREMENT,
63
35
gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -195,17 +167,21 @@ def mark_deleted(self, keys):
195
167
196
168
def model_deleted (self , model_name ):
197
169
table_name = "modelcache_llm_answer"
198
- delete_sql = "Delete from {} WHERE model='{}' " .format (table_name , model_name )
170
+ delete_sql = "Delete from {} WHERE model=? " .format (table_name )
199
171
conn = sqlite3 .connect (self ._url )
200
172
try :
201
173
cursor = conn .cursor ()
202
- resp = cursor .execute (delete_sql )
174
+ cursor .execute (delete_sql , ( model_name ,) )
203
175
conn .commit ()
176
+ # get delete rows
177
+ deleted_rows_count = cursor .rowcount
204
178
cursor .close ()
205
- conn .close ()
179
+ except sqlite3 .Error as e :
180
+ print (f"SQLite error: { e } " )
181
+ deleted_rows_count = 0 # if except, return 0
206
182
finally :
207
183
conn .close ()
208
- return resp
184
+ return deleted_rows_count
209
185
210
186
def clear_deleted_data (self ):
211
187
pass
0 commit comments