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

Code before:
        return true;

    QString downloadPath = MySettings::globalInstance()->modelPath() + modelFilename;
    QFileInfo infoLocalPath(downloadPath);
    if (infoLocalPath.exists())
        return true;
    return false;
}

void ModelList::updateModelsFromDirectory()
{
    const QString exePath = QCoreApplication::applicationDirPath() + QDir::separator();
    const QString localPath = MySettings::globalInstance()->modelPath();

    auto updateOldRemoteModels = [&](const QString& path) {
        QDirIterator it(path, QDirIterator::Subdirectories);
        while (it.hasNext()) {
            it.next();
            if (!it.fileInfo().isDir()) {
                QString filename = it.fileName();
                if(filename.endsWith(".txt")) {
                    QString apikey;
                    QString modelname(filename);
                    modelname.chop(4);
                    if(filename.startsWith("chatgpt-")) {
                        modelname.remove(0, 8);
                    }
                    QFile file(path + filename);
                    if (file.open(QIODevice::ReadWrite)) {
                        QTextStream in(&file);
                        apikey = in.readAll();
                        file.close();
                    }

                    QJsonObject obj;
                    obj.insert("apiKey", apikey);
                    obj.insert("modelName", modelname);
                    QJsonDocument doc(obj);

                    QString newfilename = "gpt4all-" + modelname + ".rmodel";
                    QFile newfile(path + newfilename);
                    if (newfile.open(QIODevice::ReadWrite)) {
                        QTextStream out(&newfile);
                        out << doc.toJson();
                        newfile.close();
                    }
                    file.remove();
                }
            }
        }
    };

Review comment (suggestion):
Whitespace issue and needs comments:
```suggestion
                if (filename.endsWith(".txt")) {
                    QString apikey;
                    QString modelname(filename);
                    modelname.chop(4); // strip ".txt" extension
                    if (filename.startsWith("chatgpt-")) {
                        modelname.remove(0, 8); // strip "chatgpt-" prefix
```

Code after:
            if (currentBaseName == baseName && currentSuffixNumber > maxSuffixNumber)
                maxSuffixNumber = currentSuffixNumber;
        }
    }

    if (baseNameExists)
        return baseName + "~" + QString::number(maxSuffixNumber + 1);

    return baseName;
}

bool ModelList::modelExists(const QString &modelFilename) const
{
    QString appPath = QCoreApplication::applicationDirPath() + modelFilename;
    QFileInfo infoAppPath(appPath);
    if (infoAppPath.exists())
        return true;

    QString downloadPath = MySettings::globalInstance()->modelPath() + modelFilename;
    QFileInfo infoLocalPath(downloadPath);
    if (infoLocalPath.exists())
        return true;
    return false;
}

void ModelList::updateModelsFromDirectory()
{
    const QString exePath = QCoreApplication::applicationDirPath() + QDir::separator();
    const QString localPath = MySettings::globalInstance()->modelPath();

    auto updateOldRemoteModels = [&](const QString& path) {
        QDirIterator it(path, QDirIterator::Subdirectories);
        while (it.hasNext()) {
            it.next();
            if (!it.fileInfo().isDir()) {
                QString filename = it.fileName();
                if (filename.endsWith(".txt")) {
                    QString apikey;
                    QString modelname(filename);
                    modelname.chop(4); // strip ".txt" extension
                    if (filename.startsWith("chatgpt-")) {
                        modelname.remove(0, 8); // strip "chatgpt-" prefix
                    }
                    QFile file(path + filename);
                    if (file.open(QIODevice::ReadWrite)) {
                        QTextStream in(&file);
                        apikey = in.readAll();
                        file.close();
                    }

                    QJsonObject obj;