2023-04-09 03:28:39 +00:00
|
|
|
#include "llm.h"
|
2023-05-08 12:23:00 +00:00
|
|
|
#include "config.h"
|
2023-04-19 01:10:06 +00:00
|
|
|
#include "download.h"
|
2023-04-27 02:05:56 +00:00
|
|
|
#include "network.h"
|
2023-04-09 03:28:39 +00:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
2023-04-11 03:34:34 +00:00
|
|
|
#include <QProcess>
|
2023-04-09 03:28:39 +00:00
|
|
|
#include <QResource>
|
2023-04-27 17:52:24 +00:00
|
|
|
#include <QSettings>
|
2023-04-10 20:33:14 +00:00
|
|
|
#include <fstream>
|
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}
|
2023-05-01 21:13:20 +00:00
|
|
|
, m_chatListModel(new ChatListModel(this))
|
2023-05-04 19:31:41 +00:00
|
|
|
, m_threadCount(std::min(4, (int32_t) std::thread::hardware_concurrency()))
|
2023-05-11 20:46:25 +00:00
|
|
|
, m_serverEnabled(false)
|
2023-05-10 03:17:21 +00:00
|
|
|
, m_compatHardware(true)
|
2023-04-18 15:42:16 +00:00
|
|
|
{
|
2023-05-04 19:31:41 +00:00
|
|
|
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
|
|
|
|
this, &LLM::aboutToQuit);
|
2023-05-11 20:46:25 +00:00
|
|
|
connect(this, &LLM::serverEnabledChanged,
|
|
|
|
m_chatListModel, &ChatListModel::handleServerEnabledChanged);
|
2023-05-08 12:23:00 +00:00
|
|
|
|
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
|
|
|
if (QString(GPT4ALL_AVX_ONLY) == "OFF") {
|
|
|
|
const bool avx(__builtin_cpu_supports("avx"));
|
|
|
|
const bool avx2(__builtin_cpu_supports("avx2"));
|
|
|
|
const bool fma(__builtin_cpu_supports("fma"));
|
|
|
|
m_compatHardware = avx && avx2 && fma;
|
|
|
|
emit compatHardwareChanged();
|
|
|
|
}
|
|
|
|
#endif
|
2023-04-18 15:42:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 03:34:34 +00:00
|
|
|
bool LLM::checkForUpdates() const
|
|
|
|
{
|
2023-04-27 11:41:23 +00:00
|
|
|
Network::globalInstance()->sendCheckForUpdates();
|
|
|
|
|
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);
|
|
|
|
}
|
2023-05-01 16:41:03 +00:00
|
|
|
|
2023-05-04 19:31:41 +00:00
|
|
|
int32_t LLM::threadCount() const
|
2023-05-01 16:41:03 +00:00
|
|
|
{
|
2023-05-04 19:31:41 +00:00
|
|
|
return m_threadCount;
|
2023-05-01 18:24:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 19:31:41 +00:00
|
|
|
void LLM::setThreadCount(int32_t n_threads)
|
2023-05-01 18:24:16 +00:00
|
|
|
{
|
2023-05-04 19:31:41 +00:00
|
|
|
if (n_threads <= 0)
|
|
|
|
n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
|
|
|
m_threadCount = n_threads;
|
|
|
|
emit threadCountChanged();
|
2023-05-01 16:41:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-11 20:46:25 +00:00
|
|
|
bool LLM::serverEnabled() const
|
|
|
|
{
|
|
|
|
return m_serverEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLM::setServerEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
if (m_serverEnabled == enabled)
|
|
|
|
return;
|
|
|
|
m_serverEnabled = enabled;
|
|
|
|
emit serverEnabledChanged();
|
|
|
|
}
|
|
|
|
|
2023-05-04 19:31:41 +00:00
|
|
|
void LLM::aboutToQuit()
|
2023-05-01 18:24:16 +00:00
|
|
|
{
|
2023-05-04 19:31:41 +00:00
|
|
|
m_chatListModel->saveChats();
|
2023-05-01 18:24:16 +00:00
|
|
|
}
|