gpt4all/gpt4all-chat/llm.cpp

104 lines
2.6 KiB
C++
Raw Normal View History

2023-04-09 03:28:39 +00:00
#include "llm.h"
#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>
#include <QDesktopServices>
2023-04-09 03:28:39 +00:00
#include <QDir>
#include <QFile>
2023-04-11 03:34:34 +00:00
#include <QProcess>
2023-04-09 03:28:39 +00:00
#include <QResource>
#include <QSettings>
#include <QUrl>
#include <QNetworkInformation>
2023-04-10 20:33:14 +00:00
#include <fstream>
2023-04-09 03:28:39 +00:00
#ifndef GPT4ALL_OFFLINE_INSTALLER
#include "network.h"
#endif
2023-04-09 03:28:39 +00:00
class MyLLM: public LLM { };
Q_GLOBAL_STATIC(MyLLM, llmInstance)
LLM *LLM::globalInstance()
{
return llmInstance();
}
LLM::LLM()
2023-04-09 03:28:39 +00:00
: QObject{nullptr}
, m_compatHardware(LLModel::Implementation::hasSupportedCPU())
{
QNetworkInformation::loadDefaultBackend();
auto * netinfo = QNetworkInformation::instance();
if (netinfo) {
connect(netinfo, &QNetworkInformation::reachabilityChanged,
this, &LLM::isNetworkOnlineChanged);
}
}
bool LLM::hasSettingsAccess() const
{
QSettings settings;
settings.sync();
return settings.status() == QSettings::NoError;
}
2023-04-11 03:34:34 +00:00
bool LLM::checkForUpdates() const
{
#ifdef GPT4ALL_OFFLINE_INSTALLER
#pragma message "offline installer build will not check for updates!"
return QDesktopServices::openUrl(QUrl("https://gpt4all.io/"));
#else
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)
2023-04-11 16:16:04 +00:00
QString tool("maintenancetool");
2023-04-11 03:34:34 +00:00
#elif defined(Q_OS_WINDOWS)
2023-04-11 16:16:04 +00:00
QString tool("maintenancetool.exe");
2023-04-11 03:34:34 +00:00
#elif defined(Q_OS_DARWIN)
2023-04-12 21:57:02 +00:00
QString tool("../../../maintenancetool.app/Contents/MacOS/maintenancetool");
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);
#endif
2023-04-11 03:34:34 +00:00
}
bool LLM::directoryExists(const QString &path)
{
const QUrl url(path);
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
const QFileInfo info(localFilePath);
return info.exists() && info.isDir();
}
bool LLM::fileExists(const QString &path)
{
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());
}
bool LLM::isNetworkOnline() const
{
auto * netinfo = QNetworkInformation::instance();
return !netinfo || netinfo->reachability() == QNetworkInformation::Reachability::Online;
}