diff --git a/gpt4all-chat/modellist.cpp b/gpt4all-chat/modellist.cpp index 93ccbe95..c0cba369 100644 --- a/gpt4all-chat/modellist.cpp +++ b/gpt4all-chat/modellist.cpp @@ -703,7 +703,7 @@ QVariant ModelList::dataInternal(const ModelInfo *info, int role) const case DirpathRole: return info->dirpath; case FilesizeRole: - return info->filesize; + return info->filesize(); case HashRole: return info->hash; case HashAlgorithmRole: @@ -861,7 +861,7 @@ void ModelList::updateData(const QString &id, const QVector case DirpathRole: info->dirpath = value.toString(); break; case FilesizeRole: - info->filesize = value.toString(); break; + info->m_filesize = value.toULongLong(); break; case HashRole: info->hash = value.toByteArray(); break; case HashAlgorithmRole: @@ -1314,7 +1314,7 @@ void ModelList::updateModelsFromDirectory() { OnlineRole, isOnline }, { CompatibleApiRole, isCompatibleApi }, { DirpathRole, info.dir().absolutePath() + "/" }, - { FilesizeRole, toFileSize(info.size()) }, + { FilesizeRole, info.size() }, }; if (isCompatibleApi) { // The data will be saved to "GPT4All.ini". @@ -1502,8 +1502,6 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) if (!versionRemoved.isEmpty() && Download::compareAppVersions(versionRemoved, currentVersion) <= 0) continue; - modelFilesize = ModelList::toFileSize(modelFilesize.toULongLong()); - const QString id = modelName; Q_ASSERT(!id.isEmpty()); @@ -1516,7 +1514,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, modelFilesize }, + { ModelList::FilesizeRole, modelFilesize.toULongLong() }, { ModelList::HashRole, modelHash }, { ModelList::HashAlgorithmRole, ModelInfo::Md5 }, { ModelList::DefaultRole, isDefault }, @@ -1574,7 +1572,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, "minimal" }, + { ModelList::FilesizeRole, 0 }, { ModelList::OnlineRole, true }, { ModelList::DescriptionRole, tr("OpenAI's ChatGPT model GPT-3.5 Turbo
%1").arg(chatGPTDesc) }, @@ -1602,7 +1600,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, "minimal" }, + { ModelList::FilesizeRole, 0 }, { ModelList::OnlineRole, true }, { ModelList::DescriptionRole, tr("OpenAI's ChatGPT model GPT-4
%1 %2").arg(chatGPTDesc).arg(chatGPT4Warn) }, @@ -1633,7 +1631,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, "minimal" }, + { ModelList::FilesizeRole, 0 }, { ModelList::OnlineRole, true }, { ModelList::DescriptionRole, tr("Mistral Tiny model
%1").arg(mistralDesc) }, @@ -1658,7 +1656,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, "minimal" }, + { ModelList::FilesizeRole, 0 }, { ModelList::OnlineRole, true }, { ModelList::DescriptionRole, tr("Mistral Small model
%1").arg(mistralDesc) }, @@ -1684,7 +1682,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, "minimal" }, + { ModelList::FilesizeRole, 0 }, { ModelList::OnlineRole, true }, { ModelList::DescriptionRole, tr("Mistral Medium model
%1").arg(mistralDesc) }, @@ -1712,7 +1710,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save) addModel(id); QVector> data { { ModelList::NameRole, modelName }, - { ModelList::FilesizeRole, "minimal" }, + { ModelList::FilesizeRole, 0 }, { ModelList::OnlineRole, true }, { ModelList::CompatibleApiRole, true }, { ModelList::DescriptionRole, @@ -2128,7 +2126,6 @@ void ModelList::handleDiscoveryItemFinished() // QString locationHeader = reply->header(QNetworkRequest::LocationHeader).toString(); QString modelFilename = reply->request().attribute(QNetworkRequest::UserMax).toString(); - QString modelFilesize = ModelList::toFileSize(QString(linkedSizeHeader).toULongLong()); QString description = tr("Created by %1.
    " "
  • Published on %2." @@ -2153,7 +2150,7 @@ void ModelList::handleDiscoveryItemFinished() QVector> data { { ModelList::NameRole, modelName }, { ModelList::FilenameRole, modelFilename }, - { ModelList::FilesizeRole, modelFilesize }, + { ModelList::FilesizeRole, QString(linkedSizeHeader).toULongLong() }, { ModelList::DescriptionRole, description }, { ModelList::IsDiscoveredRole, true }, { ModelList::UrlRole, reply->request().url() }, diff --git a/gpt4all-chat/modellist.h b/gpt4all-chat/modellist.h index 7c13da8e..b3027465 100644 --- a/gpt4all-chat/modellist.h +++ b/gpt4all-chat/modellist.h @@ -22,13 +22,14 @@ using namespace Qt::Literals::StringLiterals; + struct ModelInfo { Q_GADGET Q_PROPERTY(QString id READ id WRITE setId) Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString filename READ filename WRITE setFilename) Q_PROPERTY(QString dirpath MEMBER dirpath) - Q_PROPERTY(QString filesize MEMBER filesize) + Q_PROPERTY(QString filesize READ filesize) Q_PROPERTY(QByteArray hash MEMBER hash) Q_PROPERTY(HashAlgorithm hashAlgorithm MEMBER hashAlgorithm) Q_PROPERTY(bool calcHash MEMBER calcHash) @@ -90,6 +91,21 @@ public: QString filename() const; void setFilename(const QString &name); + QString filesize() const + { + qsizetype sz = m_filesize; + if (!sz) + return u"minimal"_s; + if (sz < 1024) + return u"%1 bytes"_s.arg(sz); + if (sz < 1024 * 1024) + return u"%1 KB"_s.arg(qreal(sz) / 1024, 0, 'g', 3); + if (sz < 1024 * 1024 * 1024) + return u"%1 MB"_s.arg(qreal(sz) / (1024 * 1024), 0, 'g', 3); + + return u"%1 GB"_s.arg(qreal(sz) / (1024 * 1024 * 1024), 0, 'g', 3); + } + QString description() const; void setDescription(const QString &d); @@ -118,7 +134,6 @@ public: void setRecency(const QDateTime &r); QString dirpath; - QString filesize; QByteArray hash; HashAlgorithm hashAlgorithm; bool calcHash = false; @@ -150,9 +165,7 @@ public: bool isEmbeddingModel = false; bool checkedEmbeddingModel = false; - bool operator==(const ModelInfo &other) const { - return m_id == other.m_id; - } + bool operator==(const ModelInfo &other) const { return m_id == other.m_id; } double temperature() const; void setTemperature(double t); @@ -193,6 +206,7 @@ private: QString m_id; QString m_name; QString m_filename; + qsizetype m_filesize; QString m_description; QString m_url; QString m_quant; @@ -209,9 +223,9 @@ private: int m_maxLength = 4096; int m_promptBatchSize = 128; int m_contextLength = 2048; - mutable int m_maxContextLength = -1; + mutable int m_maxContextLength = -1; // cache int m_gpuLayers = 100; - mutable int m_maxGpuLayers = -1; + mutable int m_maxGpuLayers = -1; // cache double m_repeatPenalty = 1.18; int m_repeatPenaltyTokens = 64; QString m_promptTemplate = "### Human:\n%1\n\n### Assistant:\n"; @@ -219,6 +233,7 @@ private: QString m_chatNamePrompt = "Describe the above conversation in seven words or less."; QString m_suggestedFollowUpPrompt = "Suggest three very short factual follow-up questions that have not been answered yet or cannot be found inspired by the previous conversation and excerpts."; friend class MySettings; + friend class ModelList; }; Q_DECLARE_METATYPE(ModelInfo) @@ -430,18 +445,6 @@ public: InstalledModels *selectableModels() const { return m_selectableModels; } DownloadableModels *downloadableModels() const { return m_downloadableModels; } - static inline QString toFileSize(quint64 sz) { - if (sz < 1024) { - return u"%1 bytes"_s.arg(sz); - } else if (sz < 1024 * 1024) { - return u"%1 KB"_s.arg(qreal(sz) / 1024, 0, 'g', 3); - } else if (sz < 1024 * 1024 * 1024) { - return u"%1 MB"_s.arg(qreal(sz) / (1024 * 1024), 0, 'g', 3); - } else { - return u"%1 GB"_s.arg(qreal(sz) / (1024 * 1024 * 1024), 0, 'g', 3); - } - } - QString incompleteDownloadPath(const QString &modelFile); bool asyncModelRequestOngoing() const { return m_asyncModelRequestOngoing; }