2023-04-09 03:28:39 +00:00
|
|
|
#include "llm.h"
|
2024-06-04 18:47:11 +00:00
|
|
|
|
2024-03-19 14:56:14 +00:00
|
|
|
#include "../gpt4all-backend/llmodel.h"
|
2023-06-26 20:34:35 +00:00
|
|
|
#include "../gpt4all-backend/sysinfo.h"
|
2023-04-09 03:28:39 +00:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2024-06-04 18:47:11 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QGlobalStatic>
|
|
|
|
#include <QNetworkInformation>
|
2023-04-11 03:34:34 +00:00
|
|
|
#include <QProcess>
|
2023-07-12 12:50:21 +00:00
|
|
|
#include <QSettings>
|
2024-01-11 17:02:39 +00:00
|
|
|
#include <QUrl>
|
2024-06-04 18:47:11 +00:00
|
|
|
#include <QtLogging>
|
|
|
|
|
2024-06-24 22:49:23 +00:00
|
|
|
#ifdef GPT4ALL_OFFLINE_INSTALLER
|
|
|
|
# include <QDesktopServices>
|
|
|
|
#else
|
2024-06-04 18:47:11 +00:00
|
|
|
# include "network.h"
|
2024-01-12 14:26:53 +00:00
|
|
|
#endif
|
|
|
|
|
2024-06-24 22:49:23 +00:00
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
2023-04-09 03:28:39 +00:00
|
|
|
class MyLLM: public LLM { };
|
|
|
|
Q_GLOBAL_STATIC(MyLLM, llmInstance)
|
|
|
|
LLM *LLM::globalInstance()
|
|
|
|
{
|
|
|
|
return llmInstance();
|
|
|
|
}
|
|
|
|
|
2023-05-01 13:10:05 +00:00
|
|
|
LLM::LLM()
|
2023-04-09 03:28:39 +00:00
|
|
|
: QObject{nullptr}
|
2024-03-19 14:56:14 +00:00
|
|
|
, m_compatHardware(LLModel::Implementation::hasSupportedCPU())
|
2023-04-18 15:42:16 +00:00
|
|
|
{
|
2024-02-07 14:53:14 +00:00
|
|
|
QNetworkInformation::loadDefaultBackend();
|
2024-02-27 18:14:24 +00:00
|
|
|
auto * netinfo = QNetworkInformation::instance();
|
|
|
|
if (netinfo) {
|
|
|
|
connect(netinfo, &QNetworkInformation::reachabilityChanged,
|
|
|
|
this, &LLM::isNetworkOnlineChanged);
|
|
|
|
}
|
2023-07-12 12:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LLM::hasSettingsAccess() const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.sync();
|
|
|
|
return settings.status() == QSettings::NoError;
|
2023-04-18 15:42:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 03:34:34 +00:00
|
|
|
bool LLM::checkForUpdates() const
|
|
|
|
{
|
2024-06-25 21:22:51 +00:00
|
|
|
#ifdef GPT4ALL_OFFLINE_INSTALLER
|
|
|
|
# pragma message(__FILE__ ": WARNING: offline installer build will not check for updates!")
|
2023-09-21 22:44:28 +00:00
|
|
|
return QDesktopServices::openUrl(QUrl("https://gpt4all.io/"));
|
2024-06-25 21:22:51 +00:00
|
|
|
#else
|
2024-04-25 17:16:52 +00:00
|
|
|
Network::globalInstance()->trackEvent("check_for_updates");
|
2023-04-27 11:41:23 +00:00
|
|
|
|
2023-04-11 03:34:34 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
2024-06-24 22:49:23 +00:00
|
|
|
QString tool = u"maintenancetool"_s;
|
2023-04-11 03:34:34 +00:00
|
|
|
#elif defined(Q_OS_WINDOWS)
|
2024-06-24 22:49:23 +00:00
|
|
|
QString tool = u"maintenancetool.exe"_s;
|
2023-04-11 03:34:34 +00:00
|
|
|
#elif defined(Q_OS_DARWIN)
|
2024-06-24 22:49:23 +00:00
|
|
|
QString tool = u"../../../maintenancetool.app/Contents/MacOS/maintenancetool"_s;
|
2023-04-11 03:34:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QString fileName = QCoreApplication::applicationDirPath()
|
2023-04-30 01:02:54 +00:00
|
|
|
+ "/../" + tool;
|
2023-04-11 03:34:34 +00:00
|
|
|
if (!QFileInfo::exists(fileName)) {
|
|
|
|
qDebug() << "Couldn't find tool at" << fileName << "so cannot check for updates!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QProcess::startDetached(fileName);
|
2024-06-25 21:22:51 +00:00
|
|
|
#endif
|
2023-04-11 03:34:34 +00:00
|
|
|
}
|
2023-05-01 16:41:03 +00:00
|
|
|
|
2024-01-11 17:02:39 +00:00
|
|
|
bool LLM::directoryExists(const QString &path)
|
2023-06-03 02:52:55 +00:00
|
|
|
{
|
|
|
|
const QUrl url(path);
|
|
|
|
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
|
|
|
|
const QFileInfo info(localFilePath);
|
|
|
|
return info.exists() && info.isDir();
|
|
|
|
}
|
|
|
|
|
2024-01-11 17:02:39 +00:00
|
|
|
bool LLM::fileExists(const QString &path)
|
2023-06-03 02:52:55 +00:00
|
|
|
{
|
|
|
|
const QUrl url(path);
|
|
|
|
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
|
|
|
|
const QFileInfo info(localFilePath);
|
|
|
|
return info.exists() && info.isFile();
|
|
|
|
}
|
|
|
|
|
2023-06-22 19:44:49 +00:00
|
|
|
qint64 LLM::systemTotalRAMInGB() const
|
|
|
|
{
|
|
|
|
return getSystemTotalRAMInGB();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LLM::systemTotalRAMInGBString() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(getSystemTotalRAMInGBString());
|
|
|
|
}
|
2024-02-07 14:53:14 +00:00
|
|
|
|
|
|
|
bool LLM::isNetworkOnline() const
|
|
|
|
{
|
2024-02-27 18:14:24 +00:00
|
|
|
auto * netinfo = QNetworkInformation::instance();
|
|
|
|
return !netinfo || netinfo->reachability() == QNetworkInformation::Reachability::Online;
|
2024-02-07 14:53:14 +00:00
|
|
|
}
|