@@ -16,47 +16,34 @@ def __init__(
1616 self .create ()
1717
1818 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+ """
4446
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- # """
6047 log_table_sql = """CREATE TABLE IF NOT EXISTS modelcache_query_log (
6148 id INTEGER PRIMARY KEY AUTOINCREMENT,
6249 gmt_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -85,19 +72,19 @@ def create(self):
8572
8673 def _insert (self , data : List ):
8774 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 ]
9179 answer_type = 0
92- embedding_data = embedding_data .tobytes ()
9380
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 )
9683
9784 conn = sqlite3 .connect (self ._url )
9885 try :
9986 cursor = conn .cursor ()
100- values = (question , answer , answer_type , model , embedding_data )
87+ values = (text , image_url , image_id , answer , answer_type , model )
10188 cursor .execute (insert_sql , values )
10289 conn .commit ()
10390 id = cursor .lastrowid
@@ -141,7 +128,7 @@ def insert_query_resp(self, query_resp, **kwargs):
141128 conn .close ()
142129
143130 def get_data_by_id (self , key : int ):
144- table_name = "modelcache_llm_answer "
131+ table_name = "open_cache_mm_answer "
145132 query_sql = "select question, answer, embedding_data, model from {} where id={}" .format (table_name , key )
146133 conn = sqlite3 .connect (self ._url )
147134 try :
@@ -160,7 +147,7 @@ def get_data_by_id(self, key: int):
160147 return None
161148
162149 def update_hit_count_by_id (self , primary_id : int ):
163- table_name = "modelcache_llm_answer "
150+ table_name = "open_cache_mm_answer "
164151 update_sql = "UPDATE {} SET hit_count = hit_count+1 WHERE id={}" .format (table_name , primary_id )
165152
166153 conn = sqlite3 .connect (self ._url )
@@ -178,7 +165,7 @@ def get_ids(self, deleted=True):
178165 pass
179166
180167 def mark_deleted (self , keys ):
181- table_name = "modelcache_llm_answer "
168+ table_name = "open_cache_mm_answer "
182169 delete_sql = "Delete from {} WHERE id in ({})" .format (table_name , "," .join ([str (i ) for i in keys ]))
183170 conn = sqlite3 .connect (self ._url )
184171 try :
@@ -193,7 +180,7 @@ def mark_deleted(self, keys):
193180 return delete_count
194181
195182 def model_deleted (self , model_name ):
196- table_name = "modelcache_llm_answer "
183+ table_name = "open_cache_mm_answer "
197184 delete_sql = "Delete from {} WHERE model='{}'" .format (table_name , model_name )
198185 conn = sqlite3 .connect (self ._url )
199186 try :
0 commit comments