Skip to content

Commit df311d2

Browse files
committed
Replace QComboBox with QLineEdit in order to get model input directly by user
1 parent 216bea6 commit df311d2

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

pyqt_openai/chat_widget/llamaOpenAIThread.py

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

66

7-
8-
# TODO
97
# Should combine with ChatThread
108
class LlamaOpenAIThread(QThread):
119
replyGenerated = Signal(str, bool, ChatMessageContainer)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from PySide6.QtCore import Qt
2+
from PySide6.QtWidgets import QLineEdit, QCompleter
3+
4+
from pyqt_openai.util.script import get_chat_model
5+
6+
7+
class ModelSearchBar(QLineEdit):
8+
def __init__(self, parent=None):
9+
super().__init__(parent)
10+
all_models = get_chat_model()
11+
# TODO LANGAUGE
12+
self.setPlaceholderText("Start typing a model name...")
13+
14+
completer = QCompleter(all_models)
15+
completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
16+
self.setCompleter(completer)

pyqt_openai/chat_widget/right_sidebar/usingAPIPage.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
O1_MODELS,
3434
SMALL_LABEL_PARAM,
3535
)
36+
from pyqt_openai.chat_widget.right_sidebar.modelSearchBar import ModelSearchBar
3637
from pyqt_openai.config_loader import CONFIG_MANAGER
3738
from pyqt_openai.lang.translations import LangClass
3839
from pyqt_openai.util.script import (
3940
getSeparator,
40-
get_chat_model,
4141
get_openai_chat_model,
4242
init_llama,
4343
)
@@ -114,14 +114,13 @@ def __initUi(self):
114114
saveSystemBtn = QPushButton(LangClass.TRANSLATIONS["Save System"])
115115
saveSystemBtn.clicked.connect(self.__saveSystem)
116116

117-
modelCmbBox = QComboBox()
118-
modelCmbBox.addItems(get_chat_model())
119-
modelCmbBox.setCurrentText(self.__model)
120-
modelCmbBox.currentTextChanged.connect(self.__modelChanged)
117+
modelSearchBar = ModelSearchBar()
118+
modelSearchBar.setText(self.__model)
119+
modelSearchBar.textChanged.connect(self.__modelChanged)
121120

122121
lay = QHBoxLayout()
123122
lay.addWidget(QLabel(LangClass.TRANSLATIONS["Model"]))
124-
lay.addWidget(modelCmbBox)
123+
lay.addWidget(modelSearchBar)
125124
lay.setContentsMargins(0, 0, 0, 0)
126125

127126
setApiBtn = ModernButton()

pyqt_openai/mainWindow.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
restart_app,
6666
show_message_box_after_change_to_restart,
6767
set_auto_start_windows,
68-
set_api_key,
6968
init_llama,
7069
)
7170
from pyqt_openai.widgets.navWidget import NavBar
@@ -103,7 +102,7 @@ def __initUi(self):
103102
self.__setTrayMenu()
104103
self.__setToolBar()
105104

106-
self.__loadApiKeyInConf()
105+
init_llama()
107106

108107
self.setCentralWidget(self.__mainWidget)
109108
self.resize(*APP_INITIAL_WINDOW_SIZE)
@@ -340,28 +339,6 @@ def __setToolBar(self):
340339
self.__settingsParamContainer.show_secondary_toolbar
341340
)
342341

343-
def __loadApiKeyInConf(self):
344-
"""
345-
This function is used to utilize the existing OpenAI, Gemini, Anthropic, and Replicate modules. While these four modules are also available in LiteLLM, this function is additionally used to leverage various features such as image generation provided by these modules.
346-
"""
347-
set_api_key(
348-
"OPENAI_API_KEY", CONFIG_MANAGER.get_general_property("OPENAI_API_KEY")
349-
)
350-
set_api_key(
351-
"GEMINI_API_KEY", CONFIG_MANAGER.get_general_property("GEMINI_API_KEY")
352-
)
353-
set_api_key(
354-
"ANTHROPIC_API_KEY",
355-
CONFIG_MANAGER.get_general_property("ANTHROPIC_API_KEY"),
356-
)
357-
set_api_key(
358-
"REPLICATE_API_KEY",
359-
CONFIG_MANAGER.get_replicate_property("REPLICATE_API_KEY"),
360-
)
361-
362-
# Set llama index directory if it exists
363-
init_llama()
364-
365342
def __showAboutDialog(self):
366343
aboutDialog = AboutDialog(self)
367344
aboutDialog.exec()

pyqt_openai/util/script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ def set_api_key(env_var_name, api_key):
725725
if env_var_name == "REPLICATE_API_KEY":
726726
REPLICATE_CLIENT.api_key = api_key
727727
os.environ["REPLICATE_API_KEY"] = api_key
728+
os.environ["REPLICATE_API_TOKEN"] = api_key
728729

729730
# Set environment variables dynamically
730731
os.environ[env_var_name] = api_key
@@ -977,7 +978,6 @@ def stream_response(response, is_g4f=False, get_content_only=True):
977978

978979
def get_api_response(args, get_content_only=True):
979980
try:
980-
print(args)
981981
response = completion(drop_params=True, **args)
982982
if args["stream"]:
983983
return stream_response(response)

0 commit comments

Comments
 (0)