将数据库的prompt换为UNIQUE唯一属性,并且插入语句换成REPLACE INTO
This commit is contained in:
@ -287,8 +287,8 @@ def diff_list(txt='', percent=0.70, switch: list = None, lst: list = None, sp=15
|
|||||||
import difflib
|
import difflib
|
||||||
count_dict = {}
|
count_dict = {}
|
||||||
if not lst:
|
if not lst:
|
||||||
lst = SqliteHandle('ai_common').get_prompt_value()
|
lst = SqliteHandle('ai_common').get_prompt_value(txt)
|
||||||
lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value())
|
lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value(txt))
|
||||||
# diff 数据,根据precent系数归类数据
|
# diff 数据,根据precent系数归类数据
|
||||||
for i in lst:
|
for i in lst:
|
||||||
found = False
|
found = False
|
||||||
@ -378,10 +378,10 @@ def prompt_retrieval(is_all, hosts='', search=False):
|
|||||||
if '所有人' in is_all:
|
if '所有人' in is_all:
|
||||||
for tab in SqliteHandle('ai_common').get_tables():
|
for tab in SqliteHandle('ai_common').get_tables():
|
||||||
if tab.startswith('prompt'):
|
if tab.startswith('prompt'):
|
||||||
data = SqliteHandle(tab).get_prompt_value()
|
data = SqliteHandle(tab).get_prompt_value(None)
|
||||||
if data: count_dict.update(data)
|
if data: count_dict.update(data)
|
||||||
elif '个人' in is_all:
|
elif '个人' in is_all:
|
||||||
data = SqliteHandle(f'prompt_{hosts}').get_prompt_value()
|
data = SqliteHandle(f'prompt_{hosts}').get_prompt_value(None)
|
||||||
if data: count_dict.update(data)
|
if data: count_dict.update(data)
|
||||||
retrieval = []
|
retrieval = []
|
||||||
if count_dict != {}:
|
if count_dict != {}:
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class SqliteHandle:
|
|||||||
self.__connect.close()
|
self.__connect.close()
|
||||||
|
|
||||||
def create_tab(self):
|
def create_tab(self):
|
||||||
self.__cursor.execute(f"CREATE TABLE `{self.__table}` ( 'prompt' TEXT, 'result' TEXT)")
|
self.__cursor.execute(f"CREATE TABLE `{self.__table}` ('prompt' TEXT UNIQUE, 'result' TEXT)")
|
||||||
|
|
||||||
def get_tables(self):
|
def get_tables(self):
|
||||||
all_tab = []
|
all_tab = []
|
||||||
@ -50,16 +50,19 @@ class SqliteHandle:
|
|||||||
all_tab.append(tab[0])
|
all_tab.append(tab[0])
|
||||||
return all_tab
|
return all_tab
|
||||||
|
|
||||||
def get_prompt_value(self):
|
def get_prompt_value(self, find):
|
||||||
temp_all = {}
|
temp_all = {}
|
||||||
result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}`").fetchall()
|
if find:
|
||||||
|
result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}` WHERE prompt LIKE '%{find}%'").fetchall()
|
||||||
|
else:
|
||||||
|
result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}`").fetchall()
|
||||||
for row in result:
|
for row in result:
|
||||||
temp_all[row[0]] = row[1]
|
temp_all[row[0]] = row[1]
|
||||||
return temp_all
|
return temp_all
|
||||||
|
|
||||||
def inset_prompt(self, prompt: dict):
|
def inset_prompt(self, prompt: dict):
|
||||||
for key in prompt:
|
for key in prompt:
|
||||||
self.__cursor.execute(f"INSERT INTO `{self.__table}` (prompt, result) VALUES (?, ?);", (str(key), str(prompt[key])))
|
self.__cursor.execute(f"REPLACE INTO `{self.__table}` (prompt, result) VALUES (?, ?);", (str(key), str(prompt[key])))
|
||||||
self.__connect.commit()
|
self.__connect.commit()
|
||||||
|
|
||||||
def delete_prompt(self):
|
def delete_prompt(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user