From c6c5e0bb4f0a6483af5dc28f0c4528705dd0c50a Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Thu, 27 Apr 2023 13:52:24 -0400 Subject: [PATCH] Always try and load default model first. Groovy is the default default. --- download.cpp | 15 ++++++++++++++- llm.cpp | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/download.cpp b/download.cpp index 4f41bbd0..82229221 100644 --- a/download.cpp +++ b/download.cpp @@ -9,6 +9,7 @@ #include #include #include +#include class MyDownload: public Download { }; Q_GLOBAL_STATIC(MyDownload, downloadInstance) @@ -198,6 +199,7 @@ void Download::parseJsonFile(const QByteArray &jsonData) return; } + QString defaultModel; QJsonArray jsonArray = document.array(); m_modelMap.clear(); @@ -208,7 +210,8 @@ void Download::parseJsonFile(const QByteArray &jsonData) QString modelFilesize = obj["filesize"].toString(); QByteArray modelMd5sum = obj["md5sum"].toString().toLatin1().constData(); bool isDefault = obj.contains("isDefault") && obj["isDefault"] == QString("true"); - + if (isDefault) + defaultModel = modelFilename; quint64 sz = modelFilesize.toULongLong(); if (sz < 1024) { modelFilesize = QString("%1 bytes").arg(sz); @@ -231,6 +234,16 @@ void Download::parseJsonFile(const QByteArray &jsonData) m_modelMap.insert(modelInfo.filename, modelInfo); } + // remove ggml- prefix and .bin suffix + Q_ASSERT(defaultModel.startsWith("ggml-")); + defaultModel = defaultModel.remove(0, 5); + Q_ASSERT(defaultModel.endsWith(".bin")); + defaultModel.chop(4); + + QSettings settings; + settings.sync(); + settings.setValue("defaultModel", defaultModel); + settings.sync(); emit modelListChanged(); } diff --git a/llm.cpp b/llm.cpp index bdc36669..5b08bcb0 100644 --- a/llm.cpp +++ b/llm.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include class MyLLM: public LLM { }; @@ -61,7 +62,12 @@ bool LLMObject::loadModel() return false; } - return loadModelPrivate(models.first()); + QSettings settings; + settings.sync(); + QString defaultModel = settings.value("defaultModel", "gpt4all-j-v1.3-groovy").toString(); + if (defaultModel.isEmpty() || !models.contains(defaultModel)) + defaultModel = models.first(); + return loadModelPrivate(defaultModel); } bool LLMObject::loadModelPrivate(const QString &modelName)