diff --git a/download.cpp b/download.cpp index 6c28c912..0f9b4bc8 100644 --- a/download.cpp +++ b/download.cpp @@ -45,42 +45,6 @@ bool operator==(const ReleaseInfo& lhs, const ReleaseInfo& rhs) { return lhs.version == rhs.version; } -QList Download::modelList() const -{ - // We make sure the default model is listed first - QList values = m_modelMap.values(); - - ModelInfo defaultInfo; - ModelInfo bestGPTJInfo; - ModelInfo bestLlamaInfo; - for (ModelInfo v : values) { - if (v.isDefault) - defaultInfo = v; - if (v.bestGPTJ) - bestGPTJInfo = v; - if (v.bestLlama) - bestLlamaInfo = v; - } - - Q_ASSERT(defaultInfo == bestGPTJInfo || defaultInfo == bestLlamaInfo); - - values.removeAll(bestLlamaInfo); - values.prepend(bestLlamaInfo); - - values.removeAll(bestGPTJInfo); - values.prepend(bestGPTJInfo); - - return values; -} - -ReleaseInfo Download::releaseInfo() const -{ - const QString currentVersion = QCoreApplication::applicationVersion(); - if (m_releaseMap.contains(currentVersion)) - return m_releaseMap.value(currentVersion); - return ReleaseInfo(); -} - bool compareVersions(const QString &a, const QString &b) { QStringList aParts = a.split('.'); QStringList bParts = b.split('.'); @@ -99,6 +63,50 @@ bool compareVersions(const QString &a, const QString &b) { 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); + + filtered.removeAll(bestLlamaInfo); + filtered.prepend(bestLlamaInfo); + + filtered.removeAll(bestGPTJInfo); + filtered.prepend(bestGPTJInfo); + + return filtered; +} + +ReleaseInfo Download::releaseInfo() const +{ + const QString currentVersion = QCoreApplication::applicationVersion(); + if (m_releaseMap.contains(currentVersion)) + return m_releaseMap.value(currentVersion); + return ReleaseInfo(); +} + 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)