Skip to content

Commit 539ddb4

Browse files
authored
Merge pull request #38 from codefuse-ai/modelcache_dev_mm
fix: sqlite does not correctly return the number of rows deleted
2 parents e1d4add + 70d2ab1 commit 539ddb4

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

modelcache/embedding/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def Huggingface(model="sentence-transformers/all-mpnet-base-v2"):
1212
return huggingface.Huggingface(model)
1313

1414

15-
def Data2VecAudio(model="facebook/data2vec-audio-base-960h"):
15+
def Data2VecAudio(model="model/text2vec-base-chinese/"):
1616
return data2vec.Data2VecAudio(model)
1717

1818

modelcache/manager/scalar_data/sql_storage_sqlite.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ def __init__(
1717
self.create()
1818

1919
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-
# """
3320
answer_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_llm_answer (
3421
id INTEGER PRIMARY KEY AUTOINCREMENT,
3522
gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -43,21 +30,6 @@ def create(self):
4330
);
4431
"""
4532

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-
# """
6133
log_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_query_log (
6234
id INTEGER PRIMARY KEY AUTOINCREMENT,
6335
gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -195,17 +167,21 @@ def mark_deleted(self, keys):
195167

196168
def model_deleted(self, model_name):
197169
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)
199171
conn = sqlite3.connect(self._url)
200172
try:
201173
cursor = conn.cursor()
202-
resp = cursor.execute(delete_sql)
174+
cursor.execute(delete_sql, (model_name,))
203175
conn.commit()
176+
# get delete rows
177+
deleted_rows_count = cursor.rowcount
204178
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
206182
finally:
207183
conn.close()
208-
return resp
184+
return deleted_rows_count
209185

210186
def clear_deleted_data(self):
211187
pass

0 commit comments

Comments
 (0)