Use sysinfo in backend.

This commit is contained in:
Adam Treat
2023-06-26 11:42:11 -04:00
parent 5e520bb775
commit a0f80453e5
5 changed files with 4 additions and 5 deletions

View File

@@ -78,7 +78,6 @@ qt_add_executable(chat
server.h server.cpp
logger.h logger.cpp
responsetext.h responsetext.cpp
sysinfo.h
${METAL_SHADER_FILE}
)

View File

@@ -1,8 +1,8 @@
#include "llm.h"
#include "config.h"
#include "sysinfo.h"
#include "chatlistmodel.h"
#include "../gpt4all-backend/llmodel.h"
#include "../gpt4all-backend/sysinfo.h"
#include "network.h"
#include <QCoreApplication>

View File

@@ -148,7 +148,7 @@ ModelInfo ModelList::defaultModelInfo() const
if (!info->installed)
continue;
defaultModel = info;
if (!hasDefaultName && defaultModel->isDefault) break;
if (!hasDefaultName) break;
if (hasDefaultName && (defaultModel->name == defaultModelName || defaultModel->filename == defaultModelName)) break;
}
if (defaultModel)

View File

@@ -1,6 +1,6 @@
#include "network.h"
#include "llm.h"
#include "chatlistmodel.h"
#include "sysinfo.h"
#include <QCoreApplication>
#include <QGuiApplication>
@@ -411,7 +411,7 @@ void Network::sendMixpanelEvent(const QString &ev, const QVector<KeyValue> &valu
if (ev == "startup") {
const QSize display = QGuiApplication::primaryScreen()->size();
properties.insert("display", QString("%1x%2").arg(display.width()).arg(display.height()));
properties.insert("ram", getSystemTotalRAMInGB());
properties.insert("ram", LLM::globalInstance()->systemTotalRAMInGB());
#if defined(Q_OS_MAC)
properties.insert("cpu", QString::fromStdString(getCPUModel()));
#endif

View File

@@ -1,61 +0,0 @@
#ifndef SYSINFO_H
#define SYSINFO_H
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>
#if defined(__linux__)
#include <unistd.h>
#elif defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(_WIN32)
#include <windows.h>
#endif
static long long getSystemTotalRAMInBytes()
{
long long totalRAM = 0;
#if defined(__linux__)
std::ifstream file("/proc/meminfo");
std::string line;
while (std::getline(file, line)) {
if (line.find("MemTotal") != std::string::npos) {
std::string memTotalStr = line.substr(line.find(":") + 1);
memTotalStr.erase(0, memTotalStr.find_first_not_of(" "));
memTotalStr = memTotalStr.substr(0, memTotalStr.find(" "));
totalRAM = std::stoll(memTotalStr) * 1024; // Convert from KB to bytes
break;
}
}
file.close();
#elif defined(__APPLE__)
int mib[2] = {CTL_HW, HW_MEMSIZE};
size_t length = sizeof(totalRAM);
sysctl(mib, 2, &totalRAM, &length, NULL, 0);
#elif defined(_WIN32)
MEMORYSTATUSEX memoryStatus;
memoryStatus.dwLength = sizeof(memoryStatus);
GlobalMemoryStatusEx(&memoryStatus);
totalRAM = memoryStatus.ullTotalPhys;
#endif
return totalRAM;
}
static double getSystemTotalRAMInGB()
{
return static_cast<double>(getSystemTotalRAMInBytes()) / (1024 * 1024 * 1024);
}
static std::string getSystemTotalRAMInGBString()
{
std::stringstream ss;
ss << std::fixed << std::setprecision(2) << getSystemTotalRAMInGB() << " GB";
return ss.str();
}
#endif // SYSINFO_H