mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-07-17 17:02:09 +00:00
Add ability to remove models.
This commit is contained in:
parent
8cdee4b0cb
commit
53c5d761a5
@ -287,6 +287,27 @@ void Download::installModel(const QString &modelFile, const QString &apiKey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Download::removeModel(const QString &modelFile)
|
||||||
|
{
|
||||||
|
const bool isChatGPT = modelFile.startsWith("chatgpt-");
|
||||||
|
const QString filePath = downloadLocalModelsPath()
|
||||||
|
+ (!isChatGPT ? "ggml-" : QString())
|
||||||
|
+ modelFile
|
||||||
|
+ (!isChatGPT ? ".bin" : ".txt");
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
qWarning() << "ERROR: Cannot remove file that does not exist" << filePath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Network::globalInstance()->sendRemoveModel(modelFile);
|
||||||
|
ModelInfo info = m_modelMap.value(modelFile);
|
||||||
|
info.installed = false;
|
||||||
|
m_modelMap.insert(modelFile, info);
|
||||||
|
file.remove();
|
||||||
|
emit modelListChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
void Download::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
||||||
{
|
{
|
||||||
QUrl url = reply->request().url();
|
QUrl url = reply->request().url();
|
||||||
|
@ -91,6 +91,7 @@ public:
|
|||||||
Q_INVOKABLE void downloadModel(const QString &modelFile);
|
Q_INVOKABLE void downloadModel(const QString &modelFile);
|
||||||
Q_INVOKABLE void cancelDownload(const QString &modelFile);
|
Q_INVOKABLE void cancelDownload(const QString &modelFile);
|
||||||
Q_INVOKABLE void installModel(const QString &modelFile, const QString &apiKey);
|
Q_INVOKABLE void installModel(const QString &modelFile, const QString &apiKey);
|
||||||
|
Q_INVOKABLE void removeModel(const QString &modelFile);
|
||||||
Q_INVOKABLE QString defaultLocalModelsPath() const;
|
Q_INVOKABLE QString defaultLocalModelsPath() const;
|
||||||
Q_INVOKABLE QString downloadLocalModelsPath() const;
|
Q_INVOKABLE QString downloadLocalModelsPath() const;
|
||||||
Q_INVOKABLE void setDownloadLocalModelsPath(const QString &modelPath);
|
Q_INVOKABLE void setDownloadLocalModelsPath(const QString &modelPath);
|
||||||
|
@ -253,6 +253,16 @@ void Network::sendInstallModel(const QString &model)
|
|||||||
sendMixpanelEvent("install_model", QVector<KeyValue>{kv});
|
sendMixpanelEvent("install_model", QVector<KeyValue>{kv});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::sendRemoveModel(const QString &model)
|
||||||
|
{
|
||||||
|
if (!m_usageStatsActive)
|
||||||
|
return;
|
||||||
|
KeyValue kv;
|
||||||
|
kv.key = QString("model");
|
||||||
|
kv.value = QJsonValue(model);
|
||||||
|
sendMixpanelEvent("remove_model", QVector<KeyValue>{kv});
|
||||||
|
}
|
||||||
|
|
||||||
void Network::sendDownloadStarted(const QString &model)
|
void Network::sendDownloadStarted(const QString &model)
|
||||||
{
|
{
|
||||||
if (!m_usageStatsActive)
|
if (!m_usageStatsActive)
|
||||||
|
@ -42,6 +42,7 @@ public Q_SLOTS:
|
|||||||
Q_INVOKABLE void sendModelDownloaderDialog();
|
Q_INVOKABLE void sendModelDownloaderDialog();
|
||||||
Q_INVOKABLE void sendResetContext(int conversationLength);
|
Q_INVOKABLE void sendResetContext(int conversationLength);
|
||||||
void sendInstallModel(const QString &model);
|
void sendInstallModel(const QString &model);
|
||||||
|
void sendRemoveModel(const QString &model);
|
||||||
void sendDownloadStarted(const QString &model);
|
void sendDownloadStarted(const QString &model);
|
||||||
void sendDownloadCanceled(const QString &model);
|
void sendDownloadCanceled(const QString &model);
|
||||||
void sendDownloadError(const QString &model, int code, const QString &errorString);
|
void sendDownloadError(const QString &model, int code, const QString &errorString);
|
||||||
|
@ -209,18 +209,47 @@ Dialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Item {
|
||||||
id: installedLabel
|
|
||||||
anchors.top: modelName.top
|
anchors.top: modelName.top
|
||||||
|
anchors.topMargin: 15
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
padding: 20
|
|
||||||
objectName: "installedLabel"
|
|
||||||
color: theme.textColor
|
|
||||||
text: qsTr("Already installed")
|
|
||||||
visible: modelData.installed
|
visible: modelData.installed
|
||||||
Accessible.role: Accessible.Paragraph
|
|
||||||
Accessible.name: text
|
Label {
|
||||||
Accessible.description: qsTr("Whether the file is already installed on your system")
|
id: installedLabel
|
||||||
|
anchors.verticalCenter: removeButton.verticalCenter
|
||||||
|
anchors.right: removeButton.left
|
||||||
|
anchors.rightMargin: 15
|
||||||
|
objectName: "installedLabel"
|
||||||
|
color: theme.textColor
|
||||||
|
text: qsTr("Already installed")
|
||||||
|
Accessible.role: Accessible.Paragraph
|
||||||
|
Accessible.name: text
|
||||||
|
Accessible.description: qsTr("Whether the file is already installed on your system")
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: removeButton
|
||||||
|
contentItem: Text {
|
||||||
|
color: theme.textColor
|
||||||
|
text: "Remove"
|
||||||
|
}
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 20
|
||||||
|
background: Rectangle {
|
||||||
|
opacity: .5
|
||||||
|
border.color: theme.backgroundLightest
|
||||||
|
border.width: 1
|
||||||
|
radius: 10
|
||||||
|
color: theme.backgroundLight
|
||||||
|
}
|
||||||
|
onClicked: {
|
||||||
|
Download.removeModel(modelData.filename);
|
||||||
|
}
|
||||||
|
Accessible.role: Accessible.Button
|
||||||
|
Accessible.name: qsTr("Remove button")
|
||||||
|
Accessible.description: qsTr("Remove button to remove model from filesystem")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
Loading…
Reference in New Issue
Block a user