Skip to content

Commit 8b2d804

Browse files
committed
Put PROVIDER_MODEL_DICT into DEFAULT_API_CONFIG, working on choosing supporting file formats feature on llamaindex
1 parent af38c1b commit 8b2d804

File tree

5 files changed

+50
-69
lines changed

5 files changed

+50
-69
lines changed

pyqt_openai/__init__.py

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -401,40 +401,15 @@ def move_bin(filename, dst_dir):
401401

402402
STT_MODEL = "whisper-1"
403403

404-
# Endpoint
405-
# https://platform.openai.com/docs/models/model-endpoint-compatibility
406-
OPENAI_ENDPOINT_DICT = {
407-
"/v1/chat/completions": ["gpt-4o", "gpt-4o-mini", "o1-preview", "o1-mini"],
408-
"/v1/completions": [
409-
"text-davinci-003",
410-
"text-davinci-002",
411-
"text-curie-001",
412-
"text-babbage-001",
413-
"text-ada-001",
414-
"davinci",
415-
"curie",
416-
"babbage",
417-
"ada",
418-
],
419-
"/v1/edits": ["text-davinci-edit-001", "code-davinci-edit-001"],
420-
"/v1/audio/transcriptions": ["whisper-1"],
421-
"/v1/audio/translations": ["whisper-1"],
422-
"/v1/fine-tunes": ["davinci", "curie", "babbage", "ada"],
423-
"/v1/embeddings": ["text-embedding-ada-002", "text-search-ada-doc-001"],
424-
"/vi/moderations": ["text-moderation-stable", "text-moderation-latest"],
425-
}
426-
427404
DEFAULT_TOKEN_CHUNK_SIZE = 1024
428405

429406
# This doesn't need endpoint
430407
OPENAI_DEFAULT_IMAGE_MODEL = "dall-e-3"
431408

432409
DEFAULT_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
433410

434-
OPENAI_CHAT_ENDPOINT = "/v1/chat/completions"
435-
436-
# Other models' configuration data
437-
DEFAULT_GEMINI_MODEL = "gemini/gemini-1.5-flash"
411+
# This has to be managed separately since some of the arguments are different with usual models
412+
O1_MODELS = ["o1-preview", "o1-mini"]
438413

439414
# Overall API configuration data
440415
DEFAULT_API_CONFIGS = [
@@ -444,6 +419,7 @@ def move_bin(filename, dst_dir):
444419
"env_var_name": "OPENAI_API_KEY",
445420
"api_key": "",
446421
"manual_url": HOW_TO_GET_OPENAI_API_KEY_URL,
422+
"model_list": ["gpt-4o", "gpt-4o-mini"] + O1_MODELS
447423
},
448424
# Azure
449425
{
@@ -503,13 +479,15 @@ def move_bin(filename, dst_dir):
503479
"api_key": "",
504480
"manual_url": HOW_TO_GET_GEMINI_API_KEY_URL,
505481
"prefix": "gemini",
482+
"model_list": ["gemini/gemini-1.5-flash", "gemini/gemini-1.5-pro"]
506483
},
507484
# Anthropic
508485
{
509486
"display_name": "Anthropic",
510487
"env_var_name": "ANTHROPIC_API_KEY",
511488
"api_key": "",
512489
"manual_url": HOW_TO_GET_CLAUDE_API_KEY_URL,
490+
"model_list": ["claude-3-5-sonnet-20240620"]
513491
},
514492
# AWS Sagemaker
515493
{
@@ -913,10 +891,6 @@ def move_bin(filename, dst_dir):
913891
},
914892
]
915893

916-
917-
# This has to be managed separately since some of the arguments are different with usual models
918-
O1_MODELS = ["o1-preview", "o1-mini"]
919-
920894
DEFAULT_LLM = "gpt-4o"
921895

922896
G4F_PROVIDER_DEFAULT = "Auto"
@@ -925,13 +899,6 @@ def move_bin(filename, dst_dir):
925899

926900
G4F_DEFAULT_IMAGE_MODEL = "flux"
927901

928-
# Dictionary that stores the platform and model pairs
929-
PROVIDER_MODEL_DICT = {
930-
"OpenAI": ["gpt-4o", "gpt-4o-mini"] + O1_MODELS,
931-
"Gemini": ["gemini/gemini-1.5-flash", "gemini/gemini-1.5-pro"],
932-
"Anthropic": ["claude-3-5-sonnet-20240620"],
933-
}
934-
935902
# Constants related to the number of messages LLM will store
936903
MAXIMUM_MESSAGES_IN_PARAMETER = 40
937904
MAXIMUM_MESSAGES_IN_PARAMETER_RANGE = 2, 1000

pyqt_openai/chat_widget/right_sidebar/llama_widget/listWidget.py renamed to pyqt_openai/chat_widget/right_sidebar/llama_widget/filesWidget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pyqt_openai.util.common import getSeparator
1919

2020

21-
class FileListWidget(QWidget):
21+
class FilesWidget(QWidget):
2222
itemUpdate = Signal(bool)
2323
onDirectorySelected = Signal()
2424
clicked = Signal(str)

pyqt_openai/chat_widget/right_sidebar/llama_widget/llamaPage.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from pyqt_openai import SMALL_LABEL_PARAM
77
from pyqt_openai.config_loader import CONFIG_MANAGER
8-
from pyqt_openai.chat_widget.right_sidebar.llama_widget.listWidget import FileListWidget
8+
from pyqt_openai.chat_widget.right_sidebar.llama_widget.filesWidget import FilesWidget
9+
from pyqt_openai.chat_widget.right_sidebar.llama_widget.supportedFileFormatsWidget import SupportedFileFormatsWidget
910
from pyqt_openai.lang.translations import LangClass
1011

1112

@@ -20,9 +21,11 @@ def __initUi(self):
2021
self.__apiCheckPreviewLbl = QLabel()
2122
self.__apiCheckPreviewLbl.setFont(QFont(*SMALL_LABEL_PARAM))
2223

23-
self.__listWidget = FileListWidget()
24-
self.__listWidget.clicked.connect(self.__setTextInBrowser)
25-
self.__listWidget.onDirectorySelected.connect(self.__onDirectorySelected)
24+
self.__filesWidget = FilesWidget()
25+
self.__filesWidget.clicked.connect(self.__setTextInBrowser)
26+
self.__filesWidget.onDirectorySelected.connect(self.__onDirectorySelected)
27+
28+
self.__supportedFileFormatsWidget = SupportedFileFormatsWidget()
2629

2730
self.__txtBrowser = QTextBrowser()
2831
self.__txtBrowser.setPlaceholderText(
@@ -33,7 +36,8 @@ def __initUi(self):
3336
self.__txtBrowser.setMaximumHeight(150)
3437

3538
lay = QVBoxLayout()
36-
lay.addWidget(self.__listWidget)
39+
lay.addWidget(self.__supportedFileFormatsWidget)
40+
lay.addWidget(self.__filesWidget)
3741
lay.addWidget(self.__txtBrowser)
3842
lay.setAlignment(Qt.AlignmentFlag.AlignTop)
3943

@@ -42,7 +46,7 @@ def __initUi(self):
4246
self.setDirectory()
4347

4448
def __onDirectorySelected(self):
45-
selected_dirname = self.__listWidget.getDirectory()
49+
selected_dirname = self.__filesWidget.getDirectory()
4650
self.onDirectorySelected.emit(selected_dirname)
4751

4852
def __setTextInBrowser(self, txt_file):
@@ -51,4 +55,4 @@ def __setTextInBrowser(self, txt_file):
5155

5256
def setDirectory(self):
5357
directory = CONFIG_MANAGER.get_general_property("llama_index_directory")
54-
self.__listWidget.setDirectory(directory, called_from_btn=False)
58+
self.__filesWidget.setDirectory(directory, called_from_btn=False)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel
2+
3+
from pyqt_openai.widgets.checkBoxListWidget import CheckBoxListWidget
4+
5+
6+
class SupportedFileFormatsWidget(QWidget):
7+
def __init__(self, parent=None):
8+
super().__init__(parent)
9+
self.__initUi()
10+
11+
def __initUi(self):
12+
self.__listWidget = CheckBoxListWidget()
13+
self.__listWidget.checkedSignal.connect(self.__sendCheckedSignal)
14+
15+
ext_lst = ['.txt', '.docx', '.xlsx', '.md', '.pdf', '.html']
16+
17+
self.__listWidget.addItems(ext_lst, checked=True)
18+
19+
lay = QVBoxLayout()
20+
# TODO LANGUAGE
21+
lay.addWidget(QLabel('Supported File Formats'))
22+
lay.addWidget(self.__listWidget)
23+
self.setLayout(lay)
24+
25+
def __sendCheckedSignal(self, r_idx, state):
26+
print(r_idx, state)

pyqt_openai/util/common.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import asyncio
99
import base64
10+
import csv
1011
import json
1112
import os
1213
import random
@@ -19,8 +20,6 @@
1920
import traceback
2021
import wave
2122
import zipfile
22-
import csv
23-
2423
from datetime import datetime
2524
from io import BytesIO
2625
from pathlib import Path
@@ -61,10 +60,7 @@
6160
AUTOSTART_REGISTRY_KEY,
6261
is_frozen,
6362
G4F_PROVIDER_DEFAULT,
64-
PROVIDER_MODEL_DICT,
6563
O1_MODELS,
66-
OPENAI_ENDPOINT_DICT,
67-
OPENAI_CHAT_ENDPOINT,
6864
STT_MODEL,
6965
DEFAULT_DATETIME_FORMAT,
7066
DEFAULT_TOKEN_CHUNK_SIZE, DEFAULT_API_CONFIGS, INDENT_SIZE,
@@ -580,9 +576,9 @@ def get_chat_model(is_g4f=False):
580576
if is_g4f:
581577
return get_g4f_models()
582578
else:
583-
all_models = [
584-
model for models in PROVIDER_MODEL_DICT.values() for model in models
585-
]
579+
all_models = []
580+
for obj in DEFAULT_API_CONFIGS:
581+
all_models.extend(obj["model_list"])
586582
return all_models
587583

588584
def get_gemini_argument(model, system, messages, cur_text, stream, images):
@@ -659,18 +655,6 @@ def set_api_key(env_var_name, api_key):
659655
# Set environment variables dynamically
660656
os.environ[env_var_name] = api_key
661657

662-
663-
def get_openai_model_endpoint(model):
664-
for k, v in OPENAI_ENDPOINT_DICT.items():
665-
endpoint_group = list(v)
666-
if model in endpoint_group:
667-
return k
668-
669-
670-
def get_openai_chat_model():
671-
return OPENAI_ENDPOINT_DICT[OPENAI_CHAT_ENDPOINT]
672-
673-
674658
def get_image_url_from_local(image, is_openai=False):
675659
"""
676660
Image is bytes, this function converts it to base64 and returns the image url
@@ -693,9 +677,9 @@ def get_message_obj(role, content):
693677

694678
# Check which provider a specific model belongs to
695679
def get_provider_from_model(model):
696-
for provider, models in PROVIDER_MODEL_DICT.items():
697-
if model in models:
698-
return provider
680+
for obj in DEFAULT_API_CONFIGS:
681+
if model in obj["model_list"]:
682+
return obj["display_name"]
699683
return None
700684

701685

0 commit comments

Comments
 (0)