Repository: nomic-ai/gpt4all
File: gpt4all-chat/download.cpp (C++)

Code before:

            QFile *tempFile = m_activeDownloads.value(modelReply);
            tempFile->deleteLater();
            m_activeDownloads.remove(modelReply);

            ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::DownloadingRole, false }});
            break;
        }
    }
}

void Download::installModel(const QString &modelFile, const QString &apiKey)
{
    Q_ASSERT(!apiKey.isEmpty());
    if (apiKey.isEmpty())
        return;

    Network::globalInstance()->sendInstallModel(modelFile);
    QString filePath = MySettings::globalInstance()->modelPath() + modelFile;
    QFile file(filePath);
    if (file.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text)) {

        QJsonObject obj;
        QString modelName(modelFile);
        modelName.remove(0, 8);
        modelName.chop(7);
        obj.insert("apiKey", apiKey);
        obj.insert("modelName", modelName);
        QJsonDocument doc(obj);

        QTextStream stream(&file);
        stream << doc.toJson();
        file.close();
        ModelList::globalInstance()->updateModelsFromDirectory();
    }

    ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::InstalledRole, true }});
}

void Download::removeModel(const QString &modelFile)
{
    const QString filePath = MySettings::globalInstance()->modelPath() + modelFile;
    QFile incompleteFile(ModelList::globalInstance()->incompleteDownloadPath(modelFile));
    if (incompleteFile.exists()) {
        incompleteFile.remove();
    }

    bool shouldRemoveInstalled = false;
    QFile file(filePath);
    if (file.exists()) {
        const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);

Review comment (suggestion):
Add comments explaining what these lines are doing, otherwise these numbers are completely magic:
```suggestion
        modelName.remove(0, 8); // strip "gpt4all-" prefix
        modelName.chop(7); // strip ".rmodel" extension
```

Code after:

            QFile *tempFile = m_activeDownloads.value(modelReply);
            tempFile->deleteLater();
            m_activeDownloads.remove(modelReply);

            ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::DownloadingRole, false }});
            break;
        }
    }
}

void Download::installModel(const QString &modelFile, const QString &apiKey)
{
    Q_ASSERT(!apiKey.isEmpty());
    if (apiKey.isEmpty())
        return;

    Network::globalInstance()->sendInstallModel(modelFile);
    QString filePath = MySettings::globalInstance()->modelPath() + modelFile;
    QFile file(filePath);
    if (file.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text)) {

        QJsonObject obj;
        QString modelName(modelFile);
        modelName.remove(0, 8); // strip "gpt4all-" prefix
        modelName.chop(7); // strip ".rmodel" extension
        obj.insert("apiKey", apiKey);
        obj.insert("modelName", modelName);
        QJsonDocument doc(obj);

        QTextStream stream(&file);
        stream << doc.toJson();
        file.close();
        ModelList::globalInstance()->updateModelsFromDirectory();
    }

    ModelList::globalInstance()->updateDataByFilename(modelFile, {{ ModelList::InstalledRole, true }});
}

void Download::removeModel(const QString &modelFile)
{
    const QString filePath = MySettings::globalInstance()->modelPath() + modelFile;
    QFile incompleteFile(ModelList::globalInstance()->incompleteDownloadPath(modelFile));
    if (incompleteFile.exists()) {
        incompleteFile.remove();
    }

    bool shouldRemoveInstalled = false;
    QFile file(filePath);
    if (file.exists()) {
        const ModelInfo info = ModelList::globalInstance()->modelInfoByFilename(modelFile);