@@ -16,47 +16,34 @@ def __init__(
16
16
self .create ()
17
17
18
18
def create (self ):
19
- # answer_table_sql = """CREATE TABLE IF NOT EXISTS `modelcache_llm_answer` (
20
- # `id` bigint(20) NOT NULL AUTO_INCREMENT comment '主键',
21
- # `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
22
- # `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
23
- # `question` text NOT NULL comment 'question',
24
- # `answer` text NOT NULL comment 'answer',
25
- # `answer_type` int(11) NOT NULL comment 'answer_type',
26
- # `hit_count` int(11) NOT NULL DEFAULT '0' comment 'hit_count',
27
- # `model` varchar(1000) NOT NULL comment 'model',
28
- # `embedding_data` blob NOT NULL comment 'embedding_data',
29
- # PRIMARY KEY(`id`)
30
- # ) AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT = 'modelcache_llm_answer';
31
- # """
32
- answer_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_llm_answer (
33
- id INTEGER PRIMARY KEY AUTOINCREMENT,
34
- gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
35
- gmt_modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
36
- question TEXT NOT NULL,
37
- answer TEXT NOT NULL,
38
- answer_type INTEGER NOT NULL,
39
- hit_count INTEGER NOT NULL DEFAULT 0,
40
- model VARCHAR(1000) NOT NULL,
41
- embedding_data BLOB NOT NULL
42
- );
43
- """
19
+ # answer_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_llm_answer (
20
+ # id INTEGER PRIMARY KEY AUTOINCREMENT,
21
+ # gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
22
+ # gmt_modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
23
+ # question TEXT NOT NULL,
24
+ # answer TEXT NOT NULL,
25
+ # answer_type INTEGER NOT NULL,
26
+ # hit_count INTEGER NOT NULL DEFAULT 0,
27
+ # model VARCHAR(1000) NOT NULL,
28
+ # embedding_data BLOB NOT NULL
29
+ # );
30
+ # """
31
+
32
+ answer_table_sql = """CREATE TABLE IF NOT EXISTS `open_cache_mm_answer` (
33
+ `id` INTEGER PRIMARY KEY AUTOINCREMENT,
34
+ `gmt_create` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
35
+ `gmt_modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
36
+ `question_text` TEXT NOT NULL,
37
+ `image_url` VARCHAR(2048) NOT NULL,
38
+ `answer` TEXT NOT NULL,
39
+ `answer_type` INTEGER NOT NULL,
40
+ `hit_count` INTEGER NOT NULL DEFAULT 0,
41
+ `model` VARCHAR(1000) NOT NULL,
42
+ `image_raw` BLOB DEFAULT NULL,
43
+ `image_id` VARCHAR(1000) DEFAULT NULL
44
+ );
45
+ """
44
46
45
- # log_table_sql = """CREATE TABLE IF NOT EXISTS `modelcache_query_log` (
46
- # `id` bigint(20) NOT NULL AUTO_INCREMENT comment '主键',
47
- # `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
48
- # `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
49
- # `error_code` int(11) NOT NULL comment 'errorCode',
50
- # `error_desc` varchar(1000) NOT NULL comment 'errorDesc',
51
- # `cache_hit` varchar(100) NOT NULL comment 'cacheHit',
52
- # `delta_time` float NOT NULL comment 'delta_time',
53
- # `model` varchar(1000) NOT NULL comment 'model',
54
- # `query` text NOT NULL comment 'query',
55
- # `hit_query` text NOT NULL comment 'hitQuery',
56
- # `answer` text NOT NULL comment 'answer',
57
- # PRIMARY KEY(`id`)
58
- # ) AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT = 'modelcache_query_log';
59
- # """
60
47
log_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_query_log (
61
48
id INTEGER PRIMARY KEY AUTOINCREMENT,
62
49
gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -85,19 +72,19 @@ def create(self):
85
72
86
73
def _insert (self , data : List ):
87
74
answer = data [0 ]
88
- question = data [1 ]
89
- embedding_data = data [2 ]
90
- model = data [3 ]
75
+ text = data [1 ]
76
+ image_url = data [2 ]
77
+ image_id = data [3 ]
78
+ model = data [4 ]
91
79
answer_type = 0
92
- embedding_data = embedding_data .tobytes ()
93
80
94
- table_name = "modelcache_llm_answer "
95
- insert_sql = "INSERT INTO {} (question, answer, answer_type, model, embedding_data ) VALUES (?, ?, ?, ?, ?)" .format (table_name )
81
+ table_name = "open_cache_mm_answer "
82
+ insert_sql = "INSERT INTO {} (question_text, image_url, image_id, answer, answer_type, model) VALUES (?, ?, ?, ?, ?, ?)" .format (table_name )
96
83
97
84
conn = sqlite3 .connect (self ._url )
98
85
try :
99
86
cursor = conn .cursor ()
100
- values = (question , answer , answer_type , model , embedding_data )
87
+ values = (text , image_url , image_id , answer , answer_type , model )
101
88
cursor .execute (insert_sql , values )
102
89
conn .commit ()
103
90
id = cursor .lastrowid
@@ -141,7 +128,7 @@ def insert_query_resp(self, query_resp, **kwargs):
141
128
conn .close ()
142
129
143
130
def get_data_by_id (self , key : int ):
144
- table_name = "modelcache_llm_answer "
131
+ table_name = "open_cache_mm_answer "
145
132
query_sql = "select question, answer, embedding_data, model from {} where id={}" .format (table_name , key )
146
133
conn = sqlite3 .connect (self ._url )
147
134
try :
@@ -160,7 +147,7 @@ def get_data_by_id(self, key: int):
160
147
return None
161
148
162
149
def update_hit_count_by_id (self , primary_id : int ):
163
- table_name = "modelcache_llm_answer "
150
+ table_name = "open_cache_mm_answer "
164
151
update_sql = "UPDATE {} SET hit_count = hit_count+1 WHERE id={}" .format (table_name , primary_id )
165
152
166
153
conn = sqlite3 .connect (self ._url )
@@ -178,7 +165,7 @@ def get_ids(self, deleted=True):
178
165
pass
179
166
180
167
def mark_deleted (self , keys ):
181
- table_name = "modelcache_llm_answer "
168
+ table_name = "open_cache_mm_answer "
182
169
delete_sql = "Delete from {} WHERE id in ({})" .format (table_name , "," .join ([str (i ) for i in keys ]))
183
170
conn = sqlite3 .connect (self ._url )
184
171
try :
@@ -193,7 +180,7 @@ def mark_deleted(self, keys):
193
180
return delete_count
194
181
195
182
def model_deleted (self , model_name ):
196
- table_name = "modelcache_llm_answer "
183
+ table_name = "open_cache_mm_answer "
197
184
delete_sql = "Delete from {} WHERE model='{}'" .format (table_name , model_name )
198
185
conn = sqlite3 .connect (self ._url )
199
186
try :
0 commit comments