--- a/OllamaInterface/OllamaWidget.py Sun Aug 25 19:44:24 2024 +0200 +++ b/OllamaInterface/OllamaWidget.py Mon Aug 26 16:01:11 2024 +0200 @@ -9,7 +9,7 @@ import json import os -from PyQt6.QtCore import QProcess, QProcessEnvironment, Qt, QTimer, pyqtSlot, QUrl +from PyQt6.QtCore import QProcess, QProcessEnvironment, Qt, QTimer, QUrl, pyqtSlot from PyQt6.QtGui import QDesktopServices from PyQt6.QtWidgets import ( QDialog, @@ -88,6 +88,8 @@ self.__localServerDialog = None self.__localServerProcess = None + self.__availableModels = [] + self.__connectClient() self.__initOllamaMenu() @@ -174,10 +176,14 @@ @param modelNames list of model names @type list[str] """ + self.__availableModels = modelNames[:] + self.modelComboBox.clear() self.modelComboBox.addItem("") - self.modelComboBox.addItems(sorted(modelNames)) + self.modelComboBox.addItems( + sorted(n.replace(":latest", "") for n in modelNames) + ) @pyqtSlot(list) def __checkHistoryModels(self, modelNames): @@ -188,10 +194,9 @@ @param modelNames list of model names @type list[str] """ + names = [n.replace(":latest", "") for n in modelNames] for index in range(self.__chatHistoryLayout.count() - 1): - self.__chatHistoryLayout.itemAt(index).widget().checkModelAvailable( - modelNames - ) + self.__chatHistoryLayout.itemAt(index).widget().checkModelAvailable(names) ############################################################################ ## Methods handling signals from the chat history widgets. @@ -601,7 +606,6 @@ """ # TODO: implement the menu and menu methods # * Pull Model - # * Remove Model ################################################################### ## Menu with Chat History related actions ################################################################### @@ -631,7 +635,9 @@ ) self.__modelMenu.addSeparator() self.__modelMenu.addAction(self.tr("Download Model"), self.__pullModel) - self.__modelMenu.addAction(self.tr("Remove Model"), self.__removeModel) + self.__removeModelAct = self.__modelMenu.addAction( + self.tr("Remove Model"), self.__removeModel + ) ################################################################### ## Menu with Local Server related actions @@ -683,6 +689,8 @@ self.__localServerProcess is not None and self.__localServerDialog is None ) + self.__removeModelAct.setEnabled(bool(self.__availableModels)) + @pyqtSlot() def __ollamaConfigure(self): """ @@ -928,5 +936,32 @@ """ Private slot to remove a model from the 'ollama' server. """ - # TODO: not implemented yet - pass + if self.__availableModels: + modelName, ok = QInputDialog.getItem( + self, + self.tr("Remove Model"), + self.tr("Select the model to be removed by the 'ollama' server:"), + [""] + sorted(self.__availableModels), + 0, + False, + ) + if ok and modelName: + deleted = self.__client.remove(modelName) + if deleted: + EricMessageBox.information( + self, + self.tr("Remove Model"), + self.tr( + "<p>The model <b>{0}</b> was deleted successfully.</p>" + ).format(modelName), + ) + self.__client.list() # reload the list of models + else: + EricMessageBox.warning( + self, + self.tr("Remove Model"), + self.tr( + "<p>The model <b>{0}</b> could not be removed from the" + " 'ollama' server.</p>" + ).format(modelName), + )