diff --git a/gpt4all-chat/qml/AddModelView.qml b/gpt4all-chat/qml/AddModelView.qml index d366b8f9..41bdfd4c 100644 --- a/gpt4all-chat/qml/AddModelView.qml +++ b/gpt4all-chat/qml/AddModelView.qml @@ -441,9 +441,7 @@ Rectangle { Layout.alignment: Qt.AlignTop | Qt.AlignHCenter visible: !isDownloading && (installed || isIncomplete) Accessible.description: qsTr("Remove model from filesystem") - onClicked: { - Download.removeModel(filename); - } + onClicked: Download.removeModel(id) } MySettingsButton { diff --git a/gpt4all-chat/qml/ModelsView.qml b/gpt4all-chat/qml/ModelsView.qml index 8a244227..f8f41c1c 100644 --- a/gpt4all-chat/qml/ModelsView.qml +++ b/gpt4all-chat/qml/ModelsView.qml @@ -221,9 +221,7 @@ Rectangle { Layout.alignment: Qt.AlignTop | Qt.AlignHCenter visible: !isDownloading && (installed || isIncomplete) Accessible.description: qsTr("Remove model from filesystem") - onClicked: { - Download.removeModel(filename); - } + onClicked: Download.removeModel(id) } MySettingsButton { diff --git a/gpt4all-chat/src/download.cpp b/gpt4all-chat/src/download.cpp index 7d183768..799ad695 100644 --- a/gpt4all-chat/src/download.cpp +++ b/gpt4all-chat/src/download.cpp @@ -328,27 +328,28 @@ void Download::installCompatibleModel(const QString &modelName, const QString &a ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::InstalledRole, true }}); } -void Download::removeModel(const QString &modelFile) +// FIXME(jared): With the current implementation, it is not possible to remove a duplicate +// model file (same filename, different subdirectory) from within GPT4All +// without restarting it. +void Download::removeModel(const QString &id) { auto *modelList = ModelList::globalInstance(); - auto *mySettings = MySettings::globalInstance(); - QFile incompleteFile(modelList->incompleteDownloadPath(modelFile)); - if (incompleteFile.exists()) - incompleteFile.remove(); + auto info = modelList->modelInfo(id); + if (info.id().isEmpty()) + return; - bool shouldRemoveInstalled = false; + Network::globalInstance()->trackEvent("remove_model", { {"model", info.filename()} }); - QFile file(mySettings->modelPath() + modelFile); - const ModelInfo info = modelList->modelInfoByFilename(modelFile); + // remove incomplete download + QFile(modelList->incompleteDownloadPath(info.filename())).remove(); - Network::globalInstance()->trackEvent("remove_model", { {"model", modelFile}, {"exists", file.exists()} }); + // remove file, if this is a real model + if (!info.isClone()) + QFile(info.path()).remove(); - if (file.exists()) { - modelList->uninstall(info); - if (!info.isClone()) - file.remove(); - } + // remove model list entry + modelList->uninstall(info); emit toastMessage(tr("Model \"%1\" is removed.").arg(info.name())); } diff --git a/gpt4all-chat/src/download.h b/gpt4all-chat/src/download.h index 9cb46a9e..a4b1541c 100644 --- a/gpt4all-chat/src/download.h +++ b/gpt4all-chat/src/download.h @@ -65,7 +65,7 @@ public: Q_INVOKABLE void cancelDownload(const QString &modelFile); Q_INVOKABLE void installModel(const QString &modelFile, const QString &apiKey); Q_INVOKABLE void installCompatibleModel(const QString &modelName, const QString &apiKey, const QString &baseUrl); - Q_INVOKABLE void removeModel(const QString &modelFile); + Q_INVOKABLE void removeModel(const QString &id); Q_INVOKABLE bool isFirstStart(bool writeVersion = false) const; public Q_SLOTS: