mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2024-10-01 01:06:10 -04:00
modellist: format file size string lazily
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
parent
8fd9f01578
commit
d49b64d24e
@ -703,7 +703,7 @@ QVariant ModelList::dataInternal(const ModelInfo *info, int role) const
|
|||||||
case DirpathRole:
|
case DirpathRole:
|
||||||
return info->dirpath;
|
return info->dirpath;
|
||||||
case FilesizeRole:
|
case FilesizeRole:
|
||||||
return info->filesize;
|
return info->filesize();
|
||||||
case HashRole:
|
case HashRole:
|
||||||
return info->hash;
|
return info->hash;
|
||||||
case HashAlgorithmRole:
|
case HashAlgorithmRole:
|
||||||
@ -861,7 +861,7 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
|
|||||||
case DirpathRole:
|
case DirpathRole:
|
||||||
info->dirpath = value.toString(); break;
|
info->dirpath = value.toString(); break;
|
||||||
case FilesizeRole:
|
case FilesizeRole:
|
||||||
info->filesize = value.toString(); break;
|
info->m_filesize = value.toULongLong(); break;
|
||||||
case HashRole:
|
case HashRole:
|
||||||
info->hash = value.toByteArray(); break;
|
info->hash = value.toByteArray(); break;
|
||||||
case HashAlgorithmRole:
|
case HashAlgorithmRole:
|
||||||
@ -1314,7 +1314,7 @@ void ModelList::updateModelsFromDirectory()
|
|||||||
{ OnlineRole, isOnline },
|
{ OnlineRole, isOnline },
|
||||||
{ CompatibleApiRole, isCompatibleApi },
|
{ CompatibleApiRole, isCompatibleApi },
|
||||||
{ DirpathRole, info.dir().absolutePath() + "/" },
|
{ DirpathRole, info.dir().absolutePath() + "/" },
|
||||||
{ FilesizeRole, toFileSize(info.size()) },
|
{ FilesizeRole, info.size() },
|
||||||
};
|
};
|
||||||
if (isCompatibleApi) {
|
if (isCompatibleApi) {
|
||||||
// The data will be saved to "GPT4All.ini".
|
// 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)
|
if (!versionRemoved.isEmpty() && Download::compareAppVersions(versionRemoved, currentVersion) <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
modelFilesize = ModelList::toFileSize(modelFilesize.toULongLong());
|
|
||||||
|
|
||||||
const QString id = modelName;
|
const QString id = modelName;
|
||||||
Q_ASSERT(!id.isEmpty());
|
Q_ASSERT(!id.isEmpty());
|
||||||
|
|
||||||
@ -1516,7 +1514,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, modelFilesize },
|
{ ModelList::FilesizeRole, modelFilesize.toULongLong() },
|
||||||
{ ModelList::HashRole, modelHash },
|
{ ModelList::HashRole, modelHash },
|
||||||
{ ModelList::HashAlgorithmRole, ModelInfo::Md5 },
|
{ ModelList::HashAlgorithmRole, ModelInfo::Md5 },
|
||||||
{ ModelList::DefaultRole, isDefault },
|
{ ModelList::DefaultRole, isDefault },
|
||||||
@ -1574,7 +1572,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, "minimal" },
|
{ ModelList::FilesizeRole, 0 },
|
||||||
{ ModelList::OnlineRole, true },
|
{ ModelList::OnlineRole, true },
|
||||||
{ ModelList::DescriptionRole,
|
{ ModelList::DescriptionRole,
|
||||||
tr("<strong>OpenAI's ChatGPT model GPT-3.5 Turbo</strong><br> %1").arg(chatGPTDesc) },
|
tr("<strong>OpenAI's ChatGPT model GPT-3.5 Turbo</strong><br> %1").arg(chatGPTDesc) },
|
||||||
@ -1602,7 +1600,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, "minimal" },
|
{ ModelList::FilesizeRole, 0 },
|
||||||
{ ModelList::OnlineRole, true },
|
{ ModelList::OnlineRole, true },
|
||||||
{ ModelList::DescriptionRole,
|
{ ModelList::DescriptionRole,
|
||||||
tr("<strong>OpenAI's ChatGPT model GPT-4</strong><br> %1 %2").arg(chatGPTDesc).arg(chatGPT4Warn) },
|
tr("<strong>OpenAI's ChatGPT model GPT-4</strong><br> %1 %2").arg(chatGPTDesc).arg(chatGPT4Warn) },
|
||||||
@ -1633,7 +1631,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, "minimal" },
|
{ ModelList::FilesizeRole, 0 },
|
||||||
{ ModelList::OnlineRole, true },
|
{ ModelList::OnlineRole, true },
|
||||||
{ ModelList::DescriptionRole,
|
{ ModelList::DescriptionRole,
|
||||||
tr("<strong>Mistral Tiny model</strong><br> %1").arg(mistralDesc) },
|
tr("<strong>Mistral Tiny model</strong><br> %1").arg(mistralDesc) },
|
||||||
@ -1658,7 +1656,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, "minimal" },
|
{ ModelList::FilesizeRole, 0 },
|
||||||
{ ModelList::OnlineRole, true },
|
{ ModelList::OnlineRole, true },
|
||||||
{ ModelList::DescriptionRole,
|
{ ModelList::DescriptionRole,
|
||||||
tr("<strong>Mistral Small model</strong><br> %1").arg(mistralDesc) },
|
tr("<strong>Mistral Small model</strong><br> %1").arg(mistralDesc) },
|
||||||
@ -1684,7 +1682,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, "minimal" },
|
{ ModelList::FilesizeRole, 0 },
|
||||||
{ ModelList::OnlineRole, true },
|
{ ModelList::OnlineRole, true },
|
||||||
{ ModelList::DescriptionRole,
|
{ ModelList::DescriptionRole,
|
||||||
tr("<strong>Mistral Medium model</strong><br> %1").arg(mistralDesc) },
|
tr("<strong>Mistral Medium model</strong><br> %1").arg(mistralDesc) },
|
||||||
@ -1712,7 +1710,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
|
|||||||
addModel(id);
|
addModel(id);
|
||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilesizeRole, "minimal" },
|
{ ModelList::FilesizeRole, 0 },
|
||||||
{ ModelList::OnlineRole, true },
|
{ ModelList::OnlineRole, true },
|
||||||
{ ModelList::CompatibleApiRole, true },
|
{ ModelList::CompatibleApiRole, true },
|
||||||
{ ModelList::DescriptionRole,
|
{ ModelList::DescriptionRole,
|
||||||
@ -2128,7 +2126,6 @@ void ModelList::handleDiscoveryItemFinished()
|
|||||||
// QString locationHeader = reply->header(QNetworkRequest::LocationHeader).toString();
|
// QString locationHeader = reply->header(QNetworkRequest::LocationHeader).toString();
|
||||||
|
|
||||||
QString modelFilename = reply->request().attribute(QNetworkRequest::UserMax).toString();
|
QString modelFilename = reply->request().attribute(QNetworkRequest::UserMax).toString();
|
||||||
QString modelFilesize = ModelList::toFileSize(QString(linkedSizeHeader).toULongLong());
|
|
||||||
|
|
||||||
QString description = tr("<strong>Created by %1.</strong><br><ul>"
|
QString description = tr("<strong>Created by %1.</strong><br><ul>"
|
||||||
"<li>Published on %2."
|
"<li>Published on %2."
|
||||||
@ -2153,7 +2150,7 @@ void ModelList::handleDiscoveryItemFinished()
|
|||||||
QVector<QPair<int, QVariant>> data {
|
QVector<QPair<int, QVariant>> data {
|
||||||
{ ModelList::NameRole, modelName },
|
{ ModelList::NameRole, modelName },
|
||||||
{ ModelList::FilenameRole, modelFilename },
|
{ ModelList::FilenameRole, modelFilename },
|
||||||
{ ModelList::FilesizeRole, modelFilesize },
|
{ ModelList::FilesizeRole, QString(linkedSizeHeader).toULongLong() },
|
||||||
{ ModelList::DescriptionRole, description },
|
{ ModelList::DescriptionRole, description },
|
||||||
{ ModelList::IsDiscoveredRole, true },
|
{ ModelList::IsDiscoveredRole, true },
|
||||||
{ ModelList::UrlRole, reply->request().url() },
|
{ ModelList::UrlRole, reply->request().url() },
|
||||||
|
@ -22,13 +22,14 @@
|
|||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
|
|
||||||
struct ModelInfo {
|
struct ModelInfo {
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
Q_PROPERTY(QString id READ id WRITE setId)
|
Q_PROPERTY(QString id READ id WRITE setId)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
Q_PROPERTY(QString filename READ filename WRITE setFilename)
|
Q_PROPERTY(QString filename READ filename WRITE setFilename)
|
||||||
Q_PROPERTY(QString dirpath MEMBER dirpath)
|
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(QByteArray hash MEMBER hash)
|
||||||
Q_PROPERTY(HashAlgorithm hashAlgorithm MEMBER hashAlgorithm)
|
Q_PROPERTY(HashAlgorithm hashAlgorithm MEMBER hashAlgorithm)
|
||||||
Q_PROPERTY(bool calcHash MEMBER calcHash)
|
Q_PROPERTY(bool calcHash MEMBER calcHash)
|
||||||
@ -90,6 +91,21 @@ public:
|
|||||||
QString filename() const;
|
QString filename() const;
|
||||||
void setFilename(const QString &name);
|
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;
|
QString description() const;
|
||||||
void setDescription(const QString &d);
|
void setDescription(const QString &d);
|
||||||
|
|
||||||
@ -118,7 +134,6 @@ public:
|
|||||||
void setRecency(const QDateTime &r);
|
void setRecency(const QDateTime &r);
|
||||||
|
|
||||||
QString dirpath;
|
QString dirpath;
|
||||||
QString filesize;
|
|
||||||
QByteArray hash;
|
QByteArray hash;
|
||||||
HashAlgorithm hashAlgorithm;
|
HashAlgorithm hashAlgorithm;
|
||||||
bool calcHash = false;
|
bool calcHash = false;
|
||||||
@ -150,9 +165,7 @@ public:
|
|||||||
bool isEmbeddingModel = false;
|
bool isEmbeddingModel = false;
|
||||||
bool checkedEmbeddingModel = false;
|
bool checkedEmbeddingModel = false;
|
||||||
|
|
||||||
bool operator==(const ModelInfo &other) const {
|
bool operator==(const ModelInfo &other) const { return m_id == other.m_id; }
|
||||||
return m_id == other.m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
double temperature() const;
|
double temperature() const;
|
||||||
void setTemperature(double t);
|
void setTemperature(double t);
|
||||||
@ -193,6 +206,7 @@ private:
|
|||||||
QString m_id;
|
QString m_id;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_filename;
|
QString m_filename;
|
||||||
|
qsizetype m_filesize;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QString m_quant;
|
QString m_quant;
|
||||||
@ -209,9 +223,9 @@ private:
|
|||||||
int m_maxLength = 4096;
|
int m_maxLength = 4096;
|
||||||
int m_promptBatchSize = 128;
|
int m_promptBatchSize = 128;
|
||||||
int m_contextLength = 2048;
|
int m_contextLength = 2048;
|
||||||
mutable int m_maxContextLength = -1;
|
mutable int m_maxContextLength = -1; // cache
|
||||||
int m_gpuLayers = 100;
|
int m_gpuLayers = 100;
|
||||||
mutable int m_maxGpuLayers = -1;
|
mutable int m_maxGpuLayers = -1; // cache
|
||||||
double m_repeatPenalty = 1.18;
|
double m_repeatPenalty = 1.18;
|
||||||
int m_repeatPenaltyTokens = 64;
|
int m_repeatPenaltyTokens = 64;
|
||||||
QString m_promptTemplate = "### Human:\n%1\n\n### Assistant:\n";
|
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_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.";
|
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 MySettings;
|
||||||
|
friend class ModelList;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(ModelInfo)
|
Q_DECLARE_METATYPE(ModelInfo)
|
||||||
|
|
||||||
@ -430,18 +445,6 @@ public:
|
|||||||
InstalledModels *selectableModels() const { return m_selectableModels; }
|
InstalledModels *selectableModels() const { return m_selectableModels; }
|
||||||
DownloadableModels *downloadableModels() const { return m_downloadableModels; }
|
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);
|
QString incompleteDownloadPath(const QString &modelFile);
|
||||||
bool asyncModelRequestOngoing() const { return m_asyncModelRequestOngoing; }
|
bool asyncModelRequestOngoing() const { return m_asyncModelRequestOngoing; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user