2023-04-08 23:28:39 -04:00
|
|
|
#include "llm.h"
|
2023-06-26 16:34:35 -04:00
|
|
|
#include "../gpt4all-backend/sysinfo.h"
|
2023-04-08 23:28:39 -04:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2024-01-11 12:02:39 -05:00
|
|
|
#include <QDesktopServices>
|
2023-04-08 23:28:39 -04:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
2023-04-10 23:34:34 -04:00
|
|
|
#include <QProcess>
|
2023-04-08 23:28:39 -04:00
|
|
|
#include <QResource>
|
2023-07-12 08:50:21 -04:00
|
|
|
#include <QSettings>
|
2024-01-11 12:02:39 -05:00
|
|
|
#include <QUrl>
|
2024-02-07 09:53:14 -05:00
|
|
|
#include <QNetworkInformation>
|
2023-04-10 16:33:14 -04:00
|
|
|
#include <fstream>
|
2023-04-08 23:28:39 -04:00
|
|
|
|
2024-01-12 09:26:53 -05:00
|
|
|
#ifndef GPT4ALL_OFFLINE_INSTALLER
|
|
|
|
#include "network.h"
|
|
|
|
#endif
|
|
|
|
|
2023-04-08 23:28:39 -04:00
|
|
|
class MyLLM: public LLM { };
|
|
|
|
Q_GLOBAL_STATIC(MyLLM, llmInstance)
|
|
|
|
LLM *LLM::globalInstance()
|
|
|
|
{
|
|
|
|
return llmInstance();
|
|
|
|
}
|
|
|
|
|
2023-05-01 09:10:05 -04:00
|
|
|
LLM::LLM()
|
2023-04-08 23:28:39 -04:00
|
|
|
: QObject{nullptr}
|
2023-05-09 23:17:21 -04:00
|
|
|
, m_compatHardware(true)
|
2023-04-18 11:42:16 -04:00
|
|
|
{
|
2023-06-04 15:28:58 -04:00
|
|
|
#if defined(__x86_64__)
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
const bool minimal(__builtin_cpu_supports("avx"));
|
|
|
|
#else
|
|
|
|
int cpuInfo[4];
|
|
|
|
__cpuid(cpuInfo, 1);
|
|
|
|
const bool minimal(cpuInfo[2] & (1 << 28));
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
const bool minimal = true; // Don't know how to handle non-x86_64
|
2023-05-08 08:23:00 -04:00
|
|
|
#endif
|
2023-06-04 15:28:58 -04:00
|
|
|
|
|
|
|
m_compatHardware = minimal;
|
2024-02-07 09:53:14 -05:00
|
|
|
|
|
|
|
QNetworkInformation::loadDefaultBackend();
|
|
|
|
connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged,
|
|
|
|
this, &LLM::isNetworkOnlineChanged);
|
2023-07-12 08:50:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LLM::hasSettingsAccess() const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.sync();
|
|
|
|
return settings.status() == QSettings::NoError;
|
2023-04-18 11:42:16 -04:00
|
|
|
}
|
|
|
|
|
2023-04-10 23:34:34 -04:00
|
|
|
bool LLM::checkForUpdates() const
|
|
|
|
{
|
2023-09-21 18:44:28 -04:00
|
|
|
#ifdef GPT4ALL_OFFLINE_INSTALLER
|
|
|
|
#pragma message "offline installer build will not check for updates!"
|
|
|
|
return QDesktopServices::openUrl(QUrl("https://gpt4all.io/"));
|
|
|
|
#else
|
2023-04-27 07:41:23 -04:00
|
|
|
Network::globalInstance()->sendCheckForUpdates();
|
|
|
|
|
2023-04-10 23:34:34 -04:00
|
|
|
#if defined(Q_OS_LINUX)
|
2023-04-11 12:16:04 -04:00
|
|
|
QString tool("maintenancetool");
|
2023-04-10 23:34:34 -04:00
|
|
|
#elif defined(Q_OS_WINDOWS)
|
2023-04-11 12:16:04 -04:00
|
|
|
QString tool("maintenancetool.exe");
|
2023-04-10 23:34:34 -04:00
|
|
|
#elif defined(Q_OS_DARWIN)
|
2023-04-12 17:57:02 -04:00
|
|
|
QString tool("../../../maintenancetool.app/Contents/MacOS/maintenancetool");
|
2023-04-10 23:34:34 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QString fileName = QCoreApplication::applicationDirPath()
|
2023-04-29 21:02:54 -04:00
|
|
|
+ "/../" + tool;
|
2023-04-10 23:34:34 -04:00
|
|
|
if (!QFileInfo::exists(fileName)) {
|
|
|
|
qDebug() << "Couldn't find tool at" << fileName << "so cannot check for updates!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QProcess::startDetached(fileName);
|
2023-09-21 18:44:28 -04:00
|
|
|
#endif
|
2023-04-10 23:34:34 -04:00
|
|
|
}
|
2023-05-01 12:41:03 -04:00
|
|
|
|
2024-01-11 12:02:39 -05:00
|
|
|
bool LLM::directoryExists(const QString &path)
|
2023-06-02 22:52:55 -04: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 12:02:39 -05:00
|
|
|
bool LLM::fileExists(const QString &path)
|
2023-06-02 22:52:55 -04: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 15:44:49 -04:00
|
|
|
qint64 LLM::systemTotalRAMInGB() const
|
|
|
|
{
|
|
|
|
return getSystemTotalRAMInGB();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LLM::systemTotalRAMInGBString() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(getSystemTotalRAMInGBString());
|
|
|
|
}
|
2024-02-07 09:53:14 -05:00
|
|
|
|
|
|
|
bool LLM::isNetworkOnline() const
|
|
|
|
{
|
|
|
|
if (!QNetworkInformation::instance())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online;
|
|
|
|
}
|