8000 Fix problems related to recent update, rename file · DataSolveProblems/pyqt-openai@daedd48 · GitHub
[go: up one dir, main page]

Skip to content

Commit daedd48

Browse files
committed
Fix problems related to recent update, rename file
1 parent 38d3bce commit daedd48

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

pyqt_openai/chat_widget/center/chatWidget.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from PySide6.QtCore import Signal
55
from PySide6.QtWidgets import QStackedWidget, QWidget, QSizePolicy, QHBoxLayout, QVBoxLayout, QMessageBox
66

7-
from pyqt_openai.config_loader import CONFIG_MANAGER
8-
from pyqt_openai.globals import LLAMAINDEX_WRAPPER, DB, get_openai_chat_model, get_argument, ChatThread
97
from pyqt_openai.chat_widget.center.chatBrowser import ChatBrowser
108
from pyqt_openai.chat_widget.center.chatHome import ChatHome
119
from pyqt_openai.chat_widget.center.menuWidget import MenuWidget
1210
from pyqt_openai.chat_widget.center.prompt import Prompt
13-
from pyqt_openai.chat_widget.chatThread import LlamaOpenAIThread
11+
from pyqt_openai.chat_widget.llamaOpenAIThread import LlamaOpenAIThread
12+
from pyqt_openai.config_loader import CONFIG_MANAGER
13+
from pyqt_openai.globals import LLAMAINDEX_WRAPPER, DB, get_argument, ChatThread
1414
from pyqt_openai.lang.translations import LangClass
1515
from pyqt_openai.models import ChatMessageContainer
1616
from pyqt_openai.widgets.notifier import NotifierWidget

pyqt_openai/chat_widget/chatThread.py renamed to pyqt_openai/chat_widget/llamaOpenAIThread.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from pyqt_openai.models import ChatMessageContainer
55

66

7+
# TODO
8+
# Should combine with ChatThread
79
class LlamaOpenAIThread(QThread):
810
replyGenerated = Signal(str, bool, ChatMessageContainer)
911
streamFinished = Signal(ChatMessageContainer)

pyqt_openai/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class ChatMessageContainer(Container):
9090
favorite: int = 0
9191
favorite_set_date: str = ""
9292
is_json_response_available: str = 0
93+
is_g4f: int = 0
94+
g4f_platform: str = ""
9395

9496
def __init__(self, **kwargs):
9597
super().__init__(**kwargs)

pyqt_openai/sqlite.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ def deletePromptEntry(self, group_id, id=None):
218218

219219
def __createThread(self):
220220
try:
221-
# Create new thread table if not exists
222-
table_name_new_exists = self.__c.execute(
221+
# Create thread table if not exists
222+
thread_tb_exists = self.__c.execute(
223223
f"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='{THREAD_TABLE_NAME}'").fetchone()[
224224
0] == 1
225-
if table_name_new_exists:
225+
if thread_tb_exists:
226226
pass
227227
else:
228228
# If user uses app for the first time, create a table
@@ -232,13 +232,15 @@ def __createThread(self):
232232
name TEXT,
233233
update_dt DATETIME,
234234
insert_dt DATETIME DEFAULT CURRENT_TIMESTAMP)''')
235-
# Create message table
236-
self.__createMessage()
237-
# Create new thread trigger if not exists
238-
trigger_name_new_exists = self.__c.execute(
235+
236+
# Create message table
237+
self.__createMessage()
238+
239+
# Create trigger if not exists
240+
thread_trigger_exists = self.__c.execute(
239241
f"SELECT count(*) FROM sqlite_master WHERE type='trigger' AND name='{THREAD_TRIGGER_NAME}'").fetchone()[
240242
0] == 1
241-
if trigger_name_new_exists:
243+
if thread_trigger_exists:
242244
pass
243245
else:
244246
# Create a trigger to update the update_dt column with the current timestamp
@@ -370,10 +372,16 @@ def __createMessage(self):
370372
f"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='{MESSAGE_TABLE_NAME}'")
371373
if self.__c.fetchone()[0] == 1:
372374
# TODO WILL_BE_REMOVED_AFTER v1.6.0
373-
# Add is_g4f, g4f_platform to the table
374-
self.__c.execute(f'ALTER TABLE {MESSAGE_TABLE_NAME} ADD '
375-
f'COLUMN is_g4f INT DEFAULT 0'
376-
f', g4f_platform VARCHAR(255)')
375+
# If there is no is_g4f column, add it
376+
self.__c.execute(f"PRAGMA table_info({MESSAGE_TABLE_NAME})")
377+
columns = self.__c.fetchall()
378+
if 'is_g4f' not in [col[1] for col in columns]:
379+
# Add is_g4f, g4f_platform to the table
380+
self.__c.execute(f'ALTER TABLE {MESSAGE_TABLE_NAME} ADD COLUMN is_g4f INT DEFAULT 0')
381+
382+
# If there is no g4f_platform column, add it
383+
if 'g4f_platform' not in [col[1] for col in columns]:
384+
self.__c.execute(f"ALTER TABLE {MESSAGE_TABLE_NAME} ADD COLUMN g4f_platform VARCHAR(255) DEFAULT ''")
377385
else:
378386
# Create message table and triggers
379387
self.__c.execute(f'''CREATE TABLE {MESSAGE_TABLE_NAME}

0 commit comments

Comments
 (0)
0