Add ability to remove models.

This commit is contained in:
Adam Treat 2023-05-16 09:32:01 -04:00 committed by AT
parent 47059ad9f1
commit b24ace372b
5 changed files with 71 additions and 9 deletions

View File

@ -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)
{
QUrl url = reply->request().url();

View File

@ -91,6 +91,7 @@ public:
Q_INVOKABLE void downloadModel(const QString &modelFile);
Q_INVOKABLE void cancelDownload(const QString &modelFile);
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 downloadLocalModelsPath() const;
Q_INVOKABLE void setDownloadLocalModelsPath(const QString &modelPath);

View File

@ -253,6 +253,16 @@ void Network::sendInstallModel(const QString &model)
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)
{
if (!m_usageStatsActive)

View File

@ -42,6 +42,7 @@ public Q_SLOTS:
Q_INVOKABLE void sendModelDownloaderDialog();
Q_INVOKABLE void sendResetContext(int conversationLength);
void sendInstallModel(const QString &model);
void sendRemoveModel(const QString &model);
void sendDownloadStarted(const QString &model);
void sendDownloadCanceled(const QString &model);
void sendDownloadError(const QString &model, int code, const QString &errorString);

View File

@ -209,20 +209,49 @@ Dialog {
}
}
Item {
anchors.top: modelName.top
anchors.topMargin: 15
anchors.right: parent.right
visible: modelData.installed
Label {
id: installedLabel
anchors.top: modelName.top
anchors.right: parent.right
padding: 20
anchors.verticalCenter: removeButton.verticalCenter
anchors.right: removeButton.left
anchors.rightMargin: 15
objectName: "installedLabel"
color: theme.textColor
text: qsTr("Already installed")
visible: modelData.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 {
visible: modelData.isChatGPT && !modelData.installed
anchors.top: modelName.top