Skip to content

Commit d993ab6

Browse files
committed
Save
1 parent 2d2e46a commit d993ab6

File tree

8 files changed

+129
-23
lines changed

8 files changed

+129
-23
lines changed

pyqt_openai/__init__.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def move_bin(filename, dst_dir):
205205
ICON_PATREON = os.path.join(ICON_PATH, "patreon.svg")
206206
ICON_SHORTCUT = os.path.join(ICON_PATH, "shortcut.svg")
207207
ICON_REALTIME_API = os.path.join(ICON_PATH, "realtime_api.svg")
208+
ICON_FILE = os.path.join(ICON_PATH, "file.svg")
208209

209210
## CUSTOMIZE
210211
DEFAULT_ICON_SIZE = (24, 24)
@@ -241,26 +242,33 @@ def move_bin(filename, dst_dir):
241242
# DEFAULT_MARKDOWN_h6_color = '#000'
242243
# DEFAULT_MARKDOWN_a_color = '#000'
243244

245+
246+
247+
command_key = "Ctrl"
248+
if sys.platform == "darwin":
249+
command_key = "Cmd"
250+
251+
244252
## SHORTCUT
245253
DEFAULT_SHORTCUT_GENERAL_ACTION = "Return"
246-
DEFAULT_SHORTCUT_FIND_PREV = "Ctrl+Shift+D"
247-
DEFAULT_SHORTCUT_FIND_NEXT = "Ctrl+D"
254+
DEFAULT_SHORTCUT_FIND_PREV = f"{command_key}+Shift+D"
255+
DEFAULT_SHORTCUT_FIND_NEXT = f"{command_key}+D"
248256
DEFAULT_SHORTCUT_FIND_CLOSE = "Escape"
249-
DEFAULT_SHORTCUT_PROMPT_BEGINNING = "Ctrl+B"
250-
DEFAULT_SHORTCUT_PROMPT_ENDING = "Ctrl+E"
251-
DEFAULT_SHORTCUT_SUPPORT_PROMPT_COMMAND = "Ctrl+Shift+P"
252-
DEFAULT_SHORTCUT_STACK_ON_TOP = "Ctrl+Shift+S"
253-
DEFAULT_SHORTCUT_SHOW_SECONDARY_TOOLBAR = "Ctrl+Shift+T"
257+
DEFAULT_SHORTCUT_PROMPT_BEGINNING = f"{command_key}+B"
258+
DEFAULT_SHORTCUT_PROMPT_ENDING = f"{command_key}+E"
259+
DEFAULT_SHORTCUT_SUPPORT_PROMPT_COMMAND = f"{command_key}+Shift+P"
260+
DEFAULT_SHORTCUT_STACK_ON_TOP = f"{command_key}+Shift+S"
261+
DEFAULT_SHORTCUT_SHOW_SECONDARY_TOOLBAR = f"{command_key}+Shift+T"
254262
DEFAULT_SHORTCUT_FOCUS_MODE = "F10"
255263
DEFAULT_SHORTCUT_FULL_SCREEN = "F11"
256-
DEFAULT_SHORTCUT_FIND = "Ctrl+F"
257-
DEFAULT_SHORTCUT_JSON_MODE = "Ctrl+J"
258-
DEFAULT_SHORTCUT_LEFT_SIDEBAR_WINDOW = "Ctrl+L"
259-
DEFAULT_SHORTCUT_RIGHT_SIDEBAR_WINDOW = "Ctrl+R"
260-
DEFAULT_SHORTCUT_CONTROL_PROMPT_WINDOW = "Ctrl+Shift+C"
261-
DEFAULT_SHORTCUT_RECORD = "Ctrl+Shift+R"
262-
DEFAULT_SHORTCUT_SETTING = "Ctrl+Alt+S"
263-
DEFAULT_SHORTCUT_SEND = "Ctrl+Return"
264+
DEFAULT_SHORTCUT_FIND = f"{command_key}+F"
265+
DEFAULT_SHORTCUT_JSON_MODE = f"{command_key}+J"
266+
DEFAULT_SHORTCUT_LEFT_SIDEBAR_WINDOW = f"{command_key}+L"
267+
DEFAULT_SHORTCUT_RIGHT_SIDEBAR_WINDOW = f"{command_key}+R"
268+
DEFAULT_SHORTCUT_CONTROL_PROMPT_WINDOW = f"{command_key}+Shift+C"
269+
DEFAULT_SHORTCUT_RECORD = f"{command_key}+Shift+R"
270+
DEFAULT_SHORTCUT_SETTING = f"{command_key}+Alt+S"
271+
DEFAULT_SHORTCUT_SEND = f"{command_key}+Return"
264272

265273
## DIRECTORY PATH & FILE'S NAME
266274
MAIN_INDEX = "main.py"
@@ -304,6 +312,8 @@ def move_bin(filename, dst_dir):
304312
THREAD_TRIGGER_NAME_OLD = "conv_tr"
305313
MESSAGE_TABLE_NAME_OLD = "conv_unit_tb"
306314

315+
CHAT_FILE_TABLE_NAME = "chat_file_tb"
316+
307317
THREAD_TABLE_NAME = "thread_tb"
308318
THREAD_TRIGGER_NAME = "thread_tr"
309319
MESSAGE_TABLE_NAME = "message_tb"
@@ -337,6 +347,7 @@ def move_bin(filename, dst_dir):
337347
PROMPT_GROUP_TABLE_NAME = "prompt_group_tb"
338348
PROMPT_ENTRY_TABLE_NAME = "prompt_entry_tb"
339349

350+
340351
# AI
341352
## OPENAI
342353
OPENAI_REQUEST_URL = "https://api.openai.com/v1/models"
@@ -420,6 +431,13 @@ def move_bin(filename, dst_dir):
420431
{"display_name": "Gemini", "env_var_name": "GEMINI_API_KEY", "api_key": ""},
421432
{"display_name": "Claude", "env_var_name": "CLAUDE_API_KEY", "api_key": ""},
422433
{"display_name": "Llama", "env_var_name": "LLAMA_API_KEY", "api_key": ""},
434+
435+
# For G4F only
436+
{"display_name": "DeepInfra", "env_var_name": "DEEPINFRA_API_KEY", "api_key": ""},
437+
{"display_name": "Groq", "env_var_name": "GROQ_API_KEY", "api_key": ""},
438+
{"display_name": "HuggingFace", "env_var_name": "HUGGINGFACE_API_KEY", "api_key": ""},
439+
{"display_name": "OpenRouter", "env_var_name": "OPENROUTER_API_KEY", "api_key": ""},
440+
{"display_name": "Perplexity API", "env_var_name": "PERPLEXITY_API_KEY", "api_key": ""}
423441
]
424442

425443
# This has to be managed separately since some of the arguments are different with usual models

pyqt_openai/chat_widget/center/aiChatUnit.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ICON_INFO,
77
ICON_FAVORITE_YES,
88
ICON_SPEAKER,
9-
WHISPER_TTS_MODEL,
9+
WHISPER_TTS_MODEL, ICON_FILE,
1010
)
1111
from pyqt_openai.config_loader import CONFIG_MANAGER
1212
from pyqt_openai.chat_widget.center.chatUnit import ChatUnit
@@ -15,6 +15,7 @@
1515
from pyqt_openai.globals import DB
1616
from pyqt_openai.util.script import stream_to_speakers
1717
from pyqt_openai.widgets.button import Button
18+
from pyqt_openai.widgets.fileTableDialog import FileTableDialog
1819

1920

2021
class AIChatUnit(ChatUnit):
@@ -39,6 +40,10 @@ def __initAIChatUi(self):
3940
self.__infoBtn.setStyleAndIcon(ICON_INFO)
4041
self.__infoBtn.clicked.connect(self.__showResponseInfoDialog)
4142

43+
self.__fileListBtn = Button()
44+
self.__fileListBtn.setStyleAndIcon(ICON_FILE)
45+
self.__fileListBtn.clicked.connect(self.__showFileListDialog)
46+
4247
self.__speakerBtn = Button()
4348
self.__speakerBtn.setStyleAndIcon(ICON_SPEAKER)
4449
self.__speakerBtn.setCheckable(True)
@@ -68,6 +73,11 @@ def __showResponseInfoDialog(self):
6873
dialog = ResponseInfoDialog(self.__result_info, parent=self)
6974
dialog.exec()
7075

76+
def __showFileListDialog(self):
77+
if self.__result_info:
78+
dialog = FileTableDialog(self.__result_info, parent=self)
79+
dialog.exec()
80+
7181
def afterResponse(self, arg):
7282
self.toggleGUI(True)
7383
self.__result_info = arg

pyqt_openai/ico/file.svg

Lines changed: 30 additions & 0 deletions
Loading

pyqt_openai/chat_widget/right_sidebar/apiWidget.py renamed to pyqt_openai/settings_dialog/apiWidget.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
QTableWidgetItem,
77
QLabel,
88
QLineEdit,
9-
QDialogButtonBox,
109
QWidget,
1110
QPushButton,
1211
)
@@ -57,14 +56,19 @@ def __initVal(self):
5756
}
5857
)
5958

60-
# Set "get api key" here
59+
# Set "get api key" to here
6160
for i, obj in enumerate(self.__api_keys):
6261
obj["get_api_key"] = {
6362
"OpenAI": HOW_TO_GET_OPENAI_API_KEY_URL,
6463
"Claude": HOW_TO_GET_CLAUDE_API_KEY_URL,
6564
"Gemini": HOW_TO_GET_GEMINI_API_KEY_URL,
6665
"Llama": HOW_TO_GET_LLAMA_API_KEY_URL,
6766
"Replicate": HOW_TO_REPLICATE,
67+
"DeepInfra": '',
68+
"Groq": '',
69+
"HuggingFace": '',
70+
"OpenRouter": '',
71+
"Perplexity API": '',
6872
}[obj["display_name"]]
6973

7074
def __initUi(self):

pyqt_openai/settings_dialog/settingsDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
QHBoxLayout,
1010
)
1111

12-
from pyqt_openai.chat_widget.right_sidebar.apiWidget import ApiWidget
12+
from pyqt_openai.settings_dialog.apiWidget import ApiWidget
1313
from pyqt_openai.lang.translations import LangClass
1414
from pyqt_openai.models import SettingsParamsContainer
1515
from pyqt_openai.settings_dialog.generalSettingsWidget import GeneralSettingsWidget

pyqt_openai/sqlite.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
PROMPT_GROUP_TABLE_NAME,
1616
PROMPT_ENTRY_TABLE_NAME,
1717
get_config_directory,
18-
DEFAULT_DATETIME_FORMAT,
18+
DEFAULT_DATETIME_FORMAT, CHAT_FILE_TABLE_NAME,
1919
)
2020
from pyqt_openai.config_loader import CONFIG_MANAGER
2121
from pyqt_openai.models import (
@@ -554,6 +554,38 @@ def updateMessage(self, id, favorite):
554554
print(f"An error occurred: {e}")
555555
raise
556556

557+
def __createChatFile(self):
558+
559+
try:
560+
# Check if the table exists
561+
self.__c.execute(
562+
f"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='{CHAT_FILE_TABLE_NAME}'"
563+
)
564+
if self.__c.fetchone()[0] == 1:
565+
# Add provider column if not exists
566+
self.__c.execute(f"PRAGMA table_info({CHAT_FILE_TABLE_NAME})")
567+
columns = self.__c.fetchall()
568+
if not any([col[1] == "provider" for col in columns]):
569+
self.__c.execute(
570+
f"ALTER TABLE {CHAT_FILE_TABLE_NAME} ADD COLUMN provider VARCHAR(255)"
571+
)
572+
else:
573+
self.__c.execute(
574+
f"""CREATE TABLE {CHAT_FILE_TABLE_NAME}
575+
(id INTEGER PRIMARY KEY,
576+
thread_id INTEGER,
577+
message_id INTEGER,
578+
name TEXT,
579+
data BLOB,
580+
update_dt DATETIME DEFAULT CURRENT_TIMESTAMP,
581+
insert_dt DATETIME DEFAULT CURRENT_TIMESTAMP)"""
582+
)
583+
# Commit the transaction
584+
self.__conn.commit()
585+
except sqlite3.Error as e:
586+
print(f"An error occurred while creating the table: {e}")
587+
raise
588+
557589
def __createImage(self):
558590
try:
559591
# Check if the table exists

pyqt_openai/util/script.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ def get_provider_models(provider: str) -> list[dict]:
856856
return [model["model"] for model in get_provider_models(provider)]
857857

858858

859-
def get_g4f_argument(model, messages, cur_text, stream):
860-
args = {"model": model, "messages": messages, "stream": stream}
859+
def get_g4f_argument(model, messages, cur_text, stream, images):
860+
args = {"model": model, "messages": messages, "stream": stream, "images": images}
861861
args["messages"].append({"role": "user", "content": cur_text})
862862
return args
863863

@@ -944,7 +944,7 @@ def get_argument(
944944
):
945945
try:
946946
if is_g4f:
947-
args = get_g4f_argument(model, messages, cur_text, stream)
947+
args = get_g4f_argument(model, messages, cur_text, stream, images)
948948
else:
949949
args = get_api_argument(
950950
model,
@@ -1000,6 +1000,7 @@ def get_api_response(args, get_content_only=True):
10001000
provider = get_provider_from_model(args["model"])
10011001
if provider == "OpenAI":
10021002
response = OPENAI_CLIENT.chat.completions.create(**args)
1003+
print(response)
10031004
if args["stream"]:
10041005
return stream_response(provider, response)
10051006
else:
@@ -1385,6 +1386,7 @@ def run(self):
13851386
self.__info.is_g4f = self.__is_g4f
13861387
# For getting the provider if it is G4F
13871388
get_content_only = not self.__info.is_g4f
1389+
13881390
if self.__input_args["stream"]:
13891391
response = get_response(
13901392
self.__input_args, self.__is_g4f, get_content_only, self.__provider
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from PySide6.QtWidgets import QDialog
2+
3+
4+
class FileTableDialog(QDialog):
5+
def __init__(self, parent=None):
6+
super().__init__(parent)
7+
self.__initUi()
8+
9+
def __initUi(self):
10+
pass

0 commit comments

Comments
 (0)