66
77from pyqt_openai .config_loader import CONFIG_MANAGER
88from pyqt_openai .globals import LLAMAINDEX_WRAPPER , DB , get_openai_chat_model , get_argument , ChatThread
9- from pyqt_openai .gpt_widget .center .chatBrowser import ChatBrowser
10- from pyqt_openai .gpt_widget .center .gptHome import GPTHome
11- from pyqt_openai .gpt_widget .center .menuWidget import MenuWidget
12- from pyqt_openai .gpt_widget .center .prompt import Prompt
13- from pyqt_openai .gpt_widget . gptThread import LlamaOpenAIThread , GPTThread
9+ from pyqt_openai .chat_widget .center .chatBrowser import ChatBrowser
10+ from pyqt_openai .chat_widget .center .chatHome import ChatHome
11+ from pyqt_openai .chat_widget .center .menuWidget import MenuWidget
12+ from pyqt_openai .chat_widget .center .prompt import Prompt
13+ from pyqt_openai .chat_widget . chatThread import LlamaOpenAIThread
1414from pyqt_openai .lang .translations import LangClass
1515from pyqt_openai .models import ChatMessageContainer
1616from pyqt_openai .widgets .notifier import NotifierWidget
@@ -28,14 +28,15 @@ def __init__(self, parent=None):
2828 def __initVal (self ):
2929 self .__cur_id = 0
3030 self .__notify_finish = CONFIG_MANAGER .get_general_property ('notify_finish' )
31+ self .__is_g4f = False
3132
3233 def __initUi (self ):
3334 # Main widget
3435 # This contains home page (at the beginning of the stack) and
3536 # widget for main view
3637 self .__mainWidget = QStackedWidget ()
3738
38- self .__homePage = GPTHome ()
39+ self .__homePage = ChatHome ()
3940 self .__browser = ChatBrowser ()
4041 self .__browser .onReplacedCurrentPage .connect (self .__mainWidget .setCurrentIndex )
4142
@@ -158,90 +159,54 @@ def __chat(self):
158159 QMessageBox .critical (self , LangClass .TRANSLATIONS ["Error" ], f'{ LangClass .TRANSLATIONS ["JSON content is not valid. Please check the JSON content field." ]} \n \n { e } ' )
159160 return
160161
161- # Get parameters for OpenAI
162- if model in get_openai_chat_model ():
163- param = get_argument ( model , system , messages , cur_text , temperature , top_p , frequency_penalty , presence_penalty , stream ,
164- use_max_tokens , max_tokens ,
165- images ,
166- is_llama_available , is_json_response_available , json_content )
167-
168- # If there is no current conversation selected on the list to the left, make a new one.
169- if self .__mainWidget .currentIndex () == 0 :
170- self .addThread .emit ()
171-
172- # Additional information of user's input
173- additional_info = {
174- 'role' : 'user' ,
175- 'content' : cur_text ,
176- 'model_name' : param ['model' ],
177- 'finish_reason' : '' ,
178- 'prompt_tokens' : '' ,
179- 'completion_tokens' : '' ,
180- 'total_tokens' : '' ,
181-
182- 'is_json_response_available' : is_json_response_available ,
183- }
184-
185- container_param = {k : v for k , v in {** param , ** additional_info }.items () if
186- k in ChatMessageContainer .get_keys ()}
187-
188- # Create a container for the user's input and output from the chatbot
189- container = ChatMessageContainer (** container_param )
190-
191- query_text = self .__prompt .getContent ()
192- self .__browser .showLabel (query_text , False , container )
162+ param = get_argument ( model , system , messages , cur_text , temperature , top_p , frequency_penalty ,
163+ presence_penalty , stream ,
164+ use_max_tokens , max_tokens ,
165+ images ,
166+ is_llama_available , is_json_response_available , json_content ,
167+ self . __is_g4f )
168+
169+ # If there is no current conversation selected on the list to the left, make a new one.
170+ if self .__mainWidget .currentIndex () == 0 :
171+ self .addThread .emit ()
172+
173+ # Additional information of user's input
174+ additional_info = {
175+ 'role' : 'user' ,
176+ 'content' : cur_text ,
177+ 'model_name' : param ['model' ],
178+ 'finish_reason' : '' ,
179+ 'prompt_tokens' : '' ,
180+ 'completion_tokens' : '' ,
181+ 'total_tokens' : '' ,
182+
183+ 'is_json_response_available' : is_json_response_available ,
184+ }
185+
186+ container_param = {k : v for k , v in {** param , ** additional_info }.items () if
187+ k in ChatMessageContainer .get_keys ()}
188+
189+ # Create a container for the user's input and output from the chatbot
190+ container = ChatMessageContainer (** container_param )
191+
192+ query_text = self .__prompt .getContent ()
193+ self .__browser .showLabel (query_text , False , container )
193194
195+ # Get parameters for OpenAI
196+ if is_llama_available :
194197 # Run a different thread based on whether the llama-index is enabled or not.
195- if is_llama_available :
196- self .__t = LlamaOpenAIThread (param , container , LLAMAINDEX_WRAPPER , query_text )
197- else :
198- self .__t = GPTThread (param , info = container )
199- self .__t .started .connect (self .__beforeGenerated )
200- self .__t .replyGenerated .connect (self .__browser .showLabel )
201- self .__t .streamFinished .connect (self .__browser .streamFinished )
202- self .__t .start ()
203- self .__t .finished .connect (self .__afterGenerated )
204-
205- # Remove image files widget from the window
206- self .__prompt .resetUploadImageFileWidget ()
198+ self .__t = LlamaOpenAIThread (param , container , LLAMAINDEX_WRAPPER , query_text )
207199 else :
208- param = get_argument (model , system , messages , cur_text , temperature , top_p , frequency_penalty , presence_penalty , stream ,
209- use_max_tokens , max_tokens ,
210- images ,
211- is_llama_available , is_json_response_available , json_content )
212-
213- # If there is no current conversation selected on the list to the left, make a new one.
214- if self .__mainWidget .currentIndex () == 0 :
215- self .addThread .emit ()
216-
217- # Additional information of user's input
218- additional_info = {
219- 'role' : 'user' ,
220- 'content' : cur_text ,
221- 'model_name' : param ['model' ],
222- 'finish_reason' : '' ,
223- 'prompt_tokens' : '' ,
224- 'completion_tokens' : '' ,
225- 'total_tokens' : '' ,
226-
227- 'is_json_response_available' : is_json_response_available ,
228- }
229-
230- container_param = {k : v for k , v in {** param , ** additional_info }.items () if
231- k in ChatMessageContainer .get_keys ()}
232-
233- # Create a container for the user's input and output from the chatbot
234- container = ChatMessageContainer (** container_param )
235-
236- query_text = self .__prompt .getContent ()
237- self .__browser .showLabel (query_text , False , container )
238-
239- self .__t = ChatThread (param , info = container )
240- self .__t .started .connect (self .__beforeGenerated )
241- self .__t .replyGenerated .connect (self .__browser .showLabel )
242- self .__t .streamFinished .connect (self .__browser .streamFinished )
243- self .__t .start ()
244- self .__t .finished .connect (self .__afterGenerated )
200+ self .__t = ChatThread (param , info = container , is_g4f = self .__is_g4f )
201+
202+ self .__t .started .connect (self .__beforeGenerated )
203+ self .__t .replyGenerated .connect (self .__browser .showLabel )
204+ self .__t .streamFinished .connect (self .__browser .streamFinished )
205+ self .__t .start ()
206+ self .__t .finished .connect (self .__afterGenerated )
207+
208+ # Remove image files widget from the window
209+ self .__prompt .resetUploadImageFileWidget ()
245210
246211 except Exception as e :
247212 # get the line of error and filename
@@ -286,6 +251,10 @@ def __bringWindowToFront(self):
286251 window .raise_ ()
287252 window .activateWindow ()
288253
254+ def setG4F (self , idx ):
255+ # Decide whether to use G4F based on the current tab index
256+ self .__is_g4f = idx == 0
257+
289258 def toggleJSON (self , f ):
290259 self .__prompt .toggleJSON (f )
291260
0 commit comments