228 """ |
228 """ |
229 names = [n.replace(":latest", "") for n in modelNames] |
229 names = [n.replace(":latest", "") for n in modelNames] |
230 for index in range(self.__chatHistoryLayout.count() - 1): |
230 for index in range(self.__chatHistoryLayout.count() - 1): |
231 self.__chatHistoryLayout.itemAt(index).widget().checkModelAvailable(names) |
231 self.__chatHistoryLayout.itemAt(index).widget().checkModelAvailable(names) |
232 |
232 |
|
233 def getSelectableModels(self): |
|
234 """ |
|
235 Public method to get a list of models to select from. |
|
236 |
|
237 @return list of models to select from |
|
238 @rtype list of str |
|
239 """ |
|
240 return [ |
|
241 self.modelComboBox.itemText(ind) |
|
242 for ind in range(self.modelComboBox.count()) |
|
243 if self.modelComboBox.itemText(ind) |
|
244 ] |
|
245 |
233 ############################################################################ |
246 ############################################################################ |
234 ## Methods handling signals from the chat history widgets. |
247 ## Methods handling signals from the chat history widgets. |
235 ############################################################################ |
248 ############################################################################ |
236 |
249 |
237 def __createHistoryWidget(self, title, model, jsonStr=None): |
250 def __createHistoryWidget(self, title, model, jsonStr=None): |
247 to None) |
260 to None) |
248 @type str (optional) |
261 @type str (optional) |
249 @return reference to the created history widget |
262 @return reference to the created history widget |
250 @rtype OllamaHistoryWidget |
263 @rtype OllamaHistoryWidget |
251 """ |
264 """ |
252 history = OllamaHistoryWidget(title=title, model=model, jsonStr=jsonStr) |
265 history = OllamaHistoryWidget( |
|
266 title=title, model=model, mainWidget=self, jsonStr=jsonStr |
|
267 ) |
253 self.__chatHistoryLayout.insertWidget( |
268 self.__chatHistoryLayout.insertWidget( |
254 self.__chatHistoryLayout.count() - 1, history |
269 self.__chatHistoryLayout.count() - 1, history |
255 ) |
270 ) |
256 |
271 |
257 history.deleteChatHistory.connect(self.__deleteHistory) |
272 history.deleteChatHistory.connect(self.__deleteHistory) |
488 historyWidget = self.__createHistoryWidget(title, model) |
503 historyWidget = self.__createHistoryWidget(title, model) |
489 hid = historyWidget.getId() |
504 hid = historyWidget.getId() |
490 chatWidget = OllamaChatWidget(hid=hid, title=title, model=model) |
505 chatWidget = OllamaChatWidget(hid=hid, title=title, model=model) |
491 index = self.chatStackWidget.addWidget(chatWidget) |
506 index = self.chatStackWidget.addWidget(chatWidget) |
492 self.chatStackWidget.setCurrentIndex(index) |
507 self.chatStackWidget.setCurrentIndex(index) |
|
508 historyWidget.parametersChanged.connect(chatWidget.chatParametersChanged) |
493 |
509 |
494 self.__updateMessageEditState() |
510 self.__updateMessageEditState() |
495 self.messageEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
511 self.messageEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
496 |
512 |
497 @pyqtSlot(str) |
513 @pyqtSlot(str) |
513 chatWidget = OllamaChatWidget( |
529 chatWidget = OllamaChatWidget( |
514 hid=hid, title=historyWidget.getTitle(), model=historyWidget.getModel() |
530 hid=hid, title=historyWidget.getTitle(), model=historyWidget.getModel() |
515 ) |
531 ) |
516 index = self.chatStackWidget.addWidget(chatWidget) |
532 index = self.chatStackWidget.addWidget(chatWidget) |
517 self.chatStackWidget.setCurrentIndex(index) |
533 self.chatStackWidget.setCurrentIndex(index) |
|
534 historyWidget.parametersChanged.connect(chatWidget.chatParametersChanged) |
518 for message in historyWidget.getMessages(): |
535 for message in historyWidget.getMessages(): |
519 chatWidget.addMessage(role=message["role"], message=message["content"]) |
536 chatWidget.addMessage(role=message["role"], message=message["content"]) |
520 else: |
537 else: |
521 # simply switch to the already existing chatWidget |
538 # simply switch to the already existing chatWidget |
522 self.chatStackWidget.setCurrentWidget(chatWidget) |
539 self.chatStackWidget.setCurrentWidget(chatWidget) |