diff --git a/download.cpp b/download.cpp index 6c28c912..0f9b4bc8 100644 --- a/download.cpp +++ b/download.cpp @@ -45,32 +45,58 @@ bool operator==(const ReleaseInfo& lhs, const ReleaseInfo& rhs) { return lhs.version == rhs.version; } +bool compareVersions(const QString &a, const QString &b) { + QStringList aParts = a.split('.'); + QStringList bParts = b.split('.'); + + for (int i = 0; i < std::min(aParts.size(), bParts.size()); ++i) { + int aInt = aParts[i].toInt(); + int bInt = bParts[i].toInt(); + + if (aInt > bInt) { + return true; + } else if (aInt < bInt) { + return false; + } + } + + return aParts.size() > bParts.size(); +} + QList Download::modelList() const { // We make sure the default model is listed first QList values = m_modelMap.values(); + const QString currentVersion = QCoreApplication::applicationVersion(); ModelInfo defaultInfo; ModelInfo bestGPTJInfo; ModelInfo bestLlamaInfo; + QList filtered; for (ModelInfo v : values) { + if (!v.requires.isEmpty() + && v.requires != currentVersion + && compareVersions(v.requires, currentVersion)) { + continue; + } if (v.isDefault) defaultInfo = v; if (v.bestGPTJ) bestGPTJInfo = v; if (v.bestLlama) bestLlamaInfo = v; + filtered.append(v); } Q_ASSERT(defaultInfo == bestGPTJInfo || defaultInfo == bestLlamaInfo); - values.removeAll(bestLlamaInfo); - values.prepend(bestLlamaInfo); + filtered.removeAll(bestLlamaInfo); + filtered.prepend(bestLlamaInfo); - values.removeAll(bestGPTJInfo); - values.prepend(bestGPTJInfo); + filtered.removeAll(bestGPTJInfo); + filtered.prepend(bestGPTJInfo); - return values; + return filtered; } ReleaseInfo Download::releaseInfo() const @@ -81,24 +107,6 @@ ReleaseInfo Download::releaseInfo() const return ReleaseInfo(); } -bool compareVersions(const QString &a, const QString &b) { - QStringList aParts = a.split('.'); - QStringList bParts = b.split('.'); - - for (int i = 0; i < std::min(aParts.size(), bParts.size()); ++i) { - int aInt = aParts[i].toInt(); - int bInt = bParts[i].toInt(); - - if (aInt > bInt) { - return true; - } else if (aInt < bInt) { - return false; - } - } - - return aParts.size() > bParts.size(); -} - bool Download::hasNewerRelease() const { const QString currentVersion = QCoreApplication::applicationVersion(); @@ -290,6 +298,7 @@ void Download::parseModelsJsonFile(const QByteArray &jsonData) QString modelFilename = obj["filename"].toString(); QString modelFilesize = obj["filesize"].toString(); + QString requires = obj["requires"].toString(); QByteArray modelMd5sum = obj["md5sum"].toString().toLatin1().constData(); bool isDefault = obj.contains("isDefault") && obj["isDefault"] == QString("true"); bool bestGPTJ = obj.contains("bestGPTJ") && obj["bestGPTJ"] == QString("true"); @@ -320,6 +329,7 @@ void Download::parseModelsJsonFile(const QByteArray &jsonData) modelInfo.bestGPTJ = bestGPTJ; modelInfo.bestLlama = bestLlama; modelInfo.description = description; + modelInfo.requires = requires; m_modelMap.insert(modelInfo.filename, modelInfo); } diff --git a/download.h b/download.h index fd63b539..ffd355e0 100644 --- a/download.h +++ b/download.h @@ -20,6 +20,7 @@ struct ModelInfo { Q_PROPERTY(bool bestGPTJ MEMBER bestGPTJ) Q_PROPERTY(bool bestLlama MEMBER bestLlama) Q_PROPERTY(QString description MEMBER description) + Q_PROPERTY(QString requires MEMBER requires) public: QString filename; @@ -31,6 +32,7 @@ public: bool bestGPTJ = false; bool bestLlama = false; QString description; + QString requires; }; Q_DECLARE_METATYPE(ModelInfo)