2023-06-27 11:54:34 -04:00
|
|
|
#include "mysettings.h"
|
2024-06-04 14:47:11 -04:00
|
|
|
|
2023-09-15 14:45:25 -04:00
|
|
|
#include "../gpt4all-backend/llmodel.h"
|
2023-06-27 11:54:34 -04:00
|
|
|
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QDebug>
|
2023-06-28 13:47:57 -04:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QGlobalStatic>
|
|
|
|
#include <QIODevice>
|
2024-06-24 18:49:23 -04:00
|
|
|
#include <QMap>
|
|
|
|
#include <QMetaObject>
|
2023-06-28 13:47:57 -04:00
|
|
|
#include <QStandardPaths>
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QThread>
|
2023-06-28 16:05:35 -04:00
|
|
|
#include <QUrl>
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QVariant>
|
2024-06-24 18:49:23 -04:00
|
|
|
#include <QtLogging>
|
2024-06-04 14:47:11 -04:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
2023-06-28 13:47:57 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
|
|
|
namespace defaults {
|
|
|
|
|
|
|
|
static const int threadCount = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
|
|
|
static const bool forceMetal = false;
|
|
|
|
static const bool networkIsActive = false;
|
|
|
|
static const bool networkUsageStatsActive = false;
|
|
|
|
static const QString device = "Auto";
|
|
|
|
|
|
|
|
} // namespace defaults
|
|
|
|
|
|
|
|
static const QVariantMap basicDefaults {
|
|
|
|
{ "chatTheme", "Light" },
|
|
|
|
{ "fontSize", "Small" },
|
|
|
|
{ "lastVersionStarted", "" },
|
|
|
|
{ "networkPort", 4891, },
|
|
|
|
{ "saveChatsContext", false },
|
|
|
|
{ "serverChat", false },
|
|
|
|
{ "userDefaultModel", "Application default" },
|
2024-06-30 19:15:01 -04:00
|
|
|
{ "localdocs/chunkSize", 512 },
|
2024-06-24 18:49:23 -04:00
|
|
|
{ "localdocs/retrievalSize", 3 },
|
|
|
|
{ "localdocs/showReferences", true },
|
|
|
|
{ "localdocs/fileExtensions", QStringList { "txt", "pdf", "md", "rst" } },
|
|
|
|
{ "localdocs/useRemoteEmbed", false },
|
|
|
|
{ "localdocs/nomicAPIKey", "" },
|
2024-06-28 12:57:57 -04:00
|
|
|
{ "localdocs/embedDevice", "Auto" },
|
2024-06-24 18:49:23 -04:00
|
|
|
{ "network/attribution", "" },
|
|
|
|
};
|
2023-06-28 13:47:57 -04:00
|
|
|
|
|
|
|
static QString defaultLocalModelsPath()
|
|
|
|
{
|
|
|
|
QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
|
|
|
|
+ "/";
|
2024-06-24 18:49:23 -04:00
|
|
|
QString testWritePath = localPath + u"test_write.txt"_s;
|
2023-06-28 13:47:57 -04:00
|
|
|
QString canonicalLocalPath = QFileInfo(localPath).canonicalFilePath() + "/";
|
|
|
|
QDir localDir(localPath);
|
|
|
|
if (!localDir.exists()) {
|
|
|
|
if (!localDir.mkpath(localPath)) {
|
|
|
|
qWarning() << "ERROR: Local download directory can't be created:" << canonicalLocalPath;
|
|
|
|
return canonicalLocalPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QFileInfo::exists(testWritePath))
|
|
|
|
return canonicalLocalPath;
|
|
|
|
|
|
|
|
QFile testWriteFile(testWritePath);
|
|
|
|
if (testWriteFile.open(QIODeviceBase::ReadWrite)) {
|
|
|
|
testWriteFile.close();
|
|
|
|
return canonicalLocalPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
qWarning() << "ERROR: Local download path appears not writeable:" << canonicalLocalPath;
|
|
|
|
return canonicalLocalPath;
|
|
|
|
}
|
2023-06-27 11:54:34 -04:00
|
|
|
|
2024-06-28 12:57:57 -04:00
|
|
|
static QStringList getDevices(bool skipKompute = false)
|
|
|
|
{
|
|
|
|
QStringList deviceList { "Auto" };
|
|
|
|
#if defined(Q_OS_MAC) && defined(__aarch64__)
|
|
|
|
deviceList << "Metal";
|
|
|
|
#else
|
|
|
|
std::vector<LLModel::GPUDevice> devices = LLModel::Implementation::availableGPUDevices();
|
|
|
|
for (LLModel::GPUDevice &d : devices) {
|
|
|
|
if (!skipKompute || strcmp(d.backend, "kompute"))
|
|
|
|
deviceList << QString::fromStdString(d.selectionName());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
deviceList << "CPU";
|
|
|
|
return deviceList;
|
|
|
|
}
|
|
|
|
|
2023-06-27 11:54:34 -04:00
|
|
|
class MyPrivateSettings: public MySettings { };
|
|
|
|
Q_GLOBAL_STATIC(MyPrivateSettings, settingsInstance)
|
|
|
|
MySettings *MySettings::globalInstance()
|
|
|
|
{
|
|
|
|
return settingsInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
MySettings::MySettings()
|
2024-06-28 12:57:57 -04:00
|
|
|
: QObject(nullptr)
|
|
|
|
, m_deviceList(getDevices())
|
|
|
|
, m_embeddingsDeviceList(getDevices(/*skipKompute*/ true))
|
2023-06-27 11:54:34 -04:00
|
|
|
{
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
QVariant MySettings::getBasicSetting(const QString &name) const
|
2023-07-01 11:34:21 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value(name, basicDefaults.value(name));
|
2023-07-01 11:34:21 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setBasicSetting(const QString &name, const QVariant &value, std::optional<QString> signal)
|
2023-07-01 11:34:21 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
if (getBasicSetting(name) == value)
|
2023-07-01 11:34:21 -04:00
|
|
|
return;
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.setValue(name, value);
|
|
|
|
QMetaObject::invokeMethod(this, u"%1Changed"_s.arg(signal.value_or(name)).toLatin1().constData());
|
2023-07-01 11:34:21 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::restoreModelDefaults(const ModelInfo &info)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelTemperature(info, info.m_temperature);
|
|
|
|
setModelTopP(info, info.m_topP);
|
|
|
|
setModelMinP(info, info.m_minP);
|
|
|
|
setModelTopK(info, info.m_topK);;
|
|
|
|
setModelMaxLength(info, info.m_maxLength);
|
|
|
|
setModelPromptBatchSize(info, info.m_promptBatchSize);
|
|
|
|
setModelContextLength(info, info.m_contextLength);
|
|
|
|
setModelGpuLayers(info, info.m_gpuLayers);
|
|
|
|
setModelRepeatPenalty(info, info.m_repeatPenalty);
|
|
|
|
setModelRepeatPenaltyTokens(info, info.m_repeatPenaltyTokens);
|
|
|
|
setModelPromptTemplate(info, info.m_promptTemplate);
|
|
|
|
setModelSystemPrompt(info, info.m_systemPrompt);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::restoreApplicationDefaults()
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setChatTheme(basicDefaults.value("chatTheme").toString());
|
|
|
|
setFontSize(basicDefaults.value("fontSize").toString());
|
|
|
|
setDevice(defaults::device);
|
|
|
|
setThreadCount(defaults::threadCount);
|
|
|
|
setSaveChatsContext(basicDefaults.value("saveChatsContext").toBool());
|
|
|
|
setServerChat(basicDefaults.value("serverChat").toBool());
|
|
|
|
setNetworkPort(basicDefaults.value("networkPort").toInt());
|
|
|
|
setModelPath(defaultLocalModelsPath());
|
|
|
|
setUserDefaultModel(basicDefaults.value("userDefaultModel").toString());
|
|
|
|
setForceMetal(defaults::forceMetal);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::restoreLocalDocsDefaults()
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setLocalDocsChunkSize(basicDefaults.value("localdocs/chunkSize").toInt());
|
|
|
|
setLocalDocsRetrievalSize(basicDefaults.value("localdocs/retrievalSize").toInt());
|
|
|
|
setLocalDocsShowReferences(basicDefaults.value("localdocs/showReferences").toBool());
|
|
|
|
setLocalDocsFileExtensions(basicDefaults.value("localdocs/fileExtensions").toStringList());
|
|
|
|
setLocalDocsUseRemoteEmbed(basicDefaults.value("localdocs/useRemoteEmbed").toBool());
|
|
|
|
setLocalDocsNomicAPIKey(basicDefaults.value("localdocs/nomicAPIKey").toString());
|
2024-06-28 12:57:57 -04:00
|
|
|
setLocalDocsEmbedDevice(basicDefaults.value("localdocs/embedDevice").toString());
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::eraseModel(const ModelInfo &info)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.remove(u"model-%1"_s.arg(info.id()));
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
QString MySettings::modelName(const ModelInfo &info) const
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value(u"model-%1/name"_s.arg(info.id()),
|
|
|
|
!info.m_name.isEmpty() ? info.m_name : info.m_filename).toString();
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelName(const ModelInfo &info, const QString &value, bool force)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
if ((modelName(info) == value || info.id().isEmpty()) && !force)
|
2024-03-05 11:31:31 -05:00
|
|
|
return;
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
if ((info.m_name == value || info.m_filename == value) && !info.shouldSaveMetadata())
|
|
|
|
m_settings.remove(u"model-%1/name"_s.arg(info.id()));
|
2024-03-05 11:31:31 -05:00
|
|
|
else
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.setValue(u"model-%1/name"_s.arg(info.id()), value);
|
|
|
|
if (!force)
|
|
|
|
emit nameChanged(info);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
static QString modelSettingName(const ModelInfo &info, const QString &name)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return u"model-%1/%2"_s.arg(info.id(), name);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
QVariant MySettings::getModelSetting(const QString &name, const ModelInfo &info) const
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value(modelSettingName(info, name), info.getFields().value(name));
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelSetting(const QString &name, const ModelInfo &info, const QVariant &value, bool force,
|
|
|
|
bool signal)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
if (!force && (info.id().isEmpty() || getModelSetting(name, info) == value))
|
2024-03-05 11:31:31 -05:00
|
|
|
return;
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
QString settingName = modelSettingName(info, name);
|
|
|
|
if (info.getFields().value(name) == value && !info.shouldSaveMetadata())
|
|
|
|
m_settings.remove(settingName);
|
2024-03-05 11:31:31 -05:00
|
|
|
else
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.setValue(settingName, value);
|
|
|
|
if (signal && !force)
|
|
|
|
QMetaObject::invokeMethod(this, u"%1Changed"_s.arg(name).toLatin1().constData(), Q_ARG(ModelInfo, info));
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
QString MySettings::modelFilename (const ModelInfo &info) const { return getModelSetting("filename", info).toString(); }
|
|
|
|
QString MySettings::modelDescription (const ModelInfo &info) const { return getModelSetting("description", info).toString(); }
|
|
|
|
QString MySettings::modelUrl (const ModelInfo &info) const { return getModelSetting("url", info).toString(); }
|
|
|
|
QString MySettings::modelQuant (const ModelInfo &info) const { return getModelSetting("quant", info).toString(); }
|
|
|
|
QString MySettings::modelType (const ModelInfo &info) const { return getModelSetting("type", info).toString(); }
|
|
|
|
bool MySettings::modelIsClone (const ModelInfo &info) const { return getModelSetting("isClone", info).toBool(); }
|
|
|
|
bool MySettings::modelIsDiscovered (const ModelInfo &info) const { return getModelSetting("isDiscovered", info).toBool(); }
|
|
|
|
int MySettings::modelLikes (const ModelInfo &info) const { return getModelSetting("likes", info).toInt(); }
|
|
|
|
int MySettings::modelDownloads (const ModelInfo &info) const { return getModelSetting("downloads", info).toInt(); }
|
|
|
|
QDateTime MySettings::modelRecency (const ModelInfo &info) const { return getModelSetting("recency", info).toDateTime(); }
|
|
|
|
double MySettings::modelTemperature (const ModelInfo &info) const { return getModelSetting("temperature", info).toDouble(); }
|
|
|
|
double MySettings::modelTopP (const ModelInfo &info) const { return getModelSetting("topP", info).toDouble(); }
|
|
|
|
double MySettings::modelMinP (const ModelInfo &info) const { return getModelSetting("minP", info).toDouble(); }
|
|
|
|
int MySettings::modelTopK (const ModelInfo &info) const { return getModelSetting("topK", info).toInt(); }
|
|
|
|
int MySettings::modelMaxLength (const ModelInfo &info) const { return getModelSetting("maxLength", info).toInt(); }
|
|
|
|
int MySettings::modelPromptBatchSize (const ModelInfo &info) const { return getModelSetting("promptBatchSize", info).toInt(); }
|
|
|
|
int MySettings::modelContextLength (const ModelInfo &info) const { return getModelSetting("contextLength", info).toInt(); }
|
|
|
|
int MySettings::modelGpuLayers (const ModelInfo &info) const { return getModelSetting("gpuLayers", info).toInt(); }
|
|
|
|
double MySettings::modelRepeatPenalty (const ModelInfo &info) const { return getModelSetting("repeatPenalty", info).toDouble(); }
|
|
|
|
int MySettings::modelRepeatPenaltyTokens(const ModelInfo &info) const { return getModelSetting("repeatPenaltyTokens", info).toInt(); }
|
|
|
|
QString MySettings::modelPromptTemplate (const ModelInfo &info) const { return getModelSetting("promptTemplate", info).toString(); }
|
|
|
|
QString MySettings::modelSystemPrompt (const ModelInfo &info) const { return getModelSetting("systemPrompt", info).toString(); }
|
2024-03-05 11:31:31 -05:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelFilename(const ModelInfo &info, const QString &value, bool force)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("filename", info, value, force, true);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelDescription(const ModelInfo &info, const QString &value, bool force)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("description", info, value, force, true);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelUrl(const ModelInfo &info, const QString &value, bool force)
|
2024-03-05 11:31:31 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("url", info, value, force);
|
2024-03-05 11:31:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelQuant(const ModelInfo &info, const QString &value, bool force)
|
2023-07-01 11:34:21 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("quant", info, value, force);
|
2023-07-01 11:34:21 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelType(const ModelInfo &info, const QString &value, bool force)
|
2023-07-01 11:34:21 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("type", info, value, force);
|
2023-07-01 11:34:21 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelIsClone(const ModelInfo &info, bool value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("isClone", info, value, force);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelIsDiscovered(const ModelInfo &info, bool value, bool force)
|
2024-02-24 17:51:34 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("isDiscovered", info, value, force);
|
2024-02-24 17:51:34 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelLikes(const ModelInfo &info, int value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("likes", info, value, force);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelDownloads(const ModelInfo &info, int value, bool force)
|
2024-02-24 17:51:34 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("downloads", info, value, force);
|
2024-02-24 17:51:34 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelRecency(const ModelInfo &info, const QDateTime &value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("recency", info, value, force);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelTemperature(const ModelInfo &info, double value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("temperature", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelTopP(const ModelInfo &info, double value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("topP", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelMinP(const ModelInfo &info, double value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("minP", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelTopK(const ModelInfo &info, int value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("topK", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelMaxLength(const ModelInfo &info, int value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("maxLength", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelPromptBatchSize(const ModelInfo &info, int value, bool force)
|
2023-12-16 17:58:15 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("promptBatchSize", info, value, force, true);
|
2023-12-16 17:58:15 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelContextLength(const ModelInfo &info, int value, bool force)
|
2023-12-16 17:58:15 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("contextLength", info, value, force, true);
|
2023-12-16 17:58:15 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelGpuLayers(const ModelInfo &info, int value, bool force)
|
2024-01-31 14:17:44 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("gpuLayers", info, value, force, true);
|
2024-01-31 14:17:44 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelRepeatPenalty(const ModelInfo &info, double value, bool force)
|
2024-01-31 14:17:44 -05:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("repeatPenalty", info, value, force, true);
|
2024-01-31 14:17:44 -05:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelRepeatPenaltyTokens(const ModelInfo &info, int value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("repeatPenaltyTokens", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelPromptTemplate(const ModelInfo &info, const QString &value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("promptTemplate", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelSystemPrompt(const ModelInfo &info, const QString &value, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
setModelSetting("systemPrompt", info, value, force, true);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int MySettings::threadCount() const
|
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
int c = m_settings.value("threadCount", defaults::threadCount).toInt();
|
2023-07-11 13:07:15 -04:00
|
|
|
// The old thread setting likely left many people with 0 in settings config file, which means
|
|
|
|
// we should reset it to the default going forward
|
|
|
|
if (c <= 0)
|
2024-06-24 18:49:23 -04:00
|
|
|
c = defaults::threadCount;
|
2023-07-10 16:52:32 -04:00
|
|
|
c = std::max(c, 1);
|
|
|
|
c = std::min(c, QThread::idealThreadCount());
|
|
|
|
return c;
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setThreadCount(int value)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
if (threadCount() == value)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
value = std::max(value, 1);
|
|
|
|
value = std::min(value, QThread::idealThreadCount());
|
|
|
|
m_settings.setValue("threadCount", value);
|
2023-06-28 13:47:57 -04:00
|
|
|
emit threadCountChanged();
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
bool MySettings::saveChatsContext() const { return getBasicSetting("saveChatsContext" ).toBool(); }
|
|
|
|
bool MySettings::serverChat() const { return getBasicSetting("serverChat" ).toBool(); }
|
|
|
|
int MySettings::networkPort() const { return getBasicSetting("networkPort" ).toInt(); }
|
|
|
|
QString MySettings::userDefaultModel() const { return getBasicSetting("userDefaultModel" ).toString(); }
|
|
|
|
QString MySettings::chatTheme() const { return getBasicSetting("chatTheme" ).toString(); }
|
|
|
|
QString MySettings::fontSize() const { return getBasicSetting("fontSize" ).toString(); }
|
|
|
|
QString MySettings::lastVersionStarted() const { return getBasicSetting("lastVersionStarted" ).toString(); }
|
|
|
|
int MySettings::localDocsChunkSize() const { return getBasicSetting("localdocs/chunkSize" ).toInt(); }
|
|
|
|
int MySettings::localDocsRetrievalSize() const { return getBasicSetting("localdocs/retrievalSize" ).toInt(); }
|
|
|
|
bool MySettings::localDocsShowReferences() const { return getBasicSetting("localdocs/showReferences").toBool(); }
|
|
|
|
QStringList MySettings::localDocsFileExtensions() const { return getBasicSetting("localdocs/fileExtensions").toStringList(); }
|
|
|
|
bool MySettings::localDocsUseRemoteEmbed() const { return getBasicSetting("localdocs/useRemoteEmbed").toBool(); }
|
|
|
|
QString MySettings::localDocsNomicAPIKey() const { return getBasicSetting("localdocs/nomicAPIKey" ).toString(); }
|
2024-06-28 12:57:57 -04:00
|
|
|
QString MySettings::localDocsEmbedDevice() const { return getBasicSetting("localdocs/embedDevice" ).toString(); }
|
2024-06-24 18:49:23 -04:00
|
|
|
QString MySettings::networkAttribution() const { return getBasicSetting("network/attribution" ).toString(); }
|
|
|
|
|
|
|
|
void MySettings::setSaveChatsContext(bool value) { setBasicSetting("saveChatsContext", value); }
|
|
|
|
void MySettings::setServerChat(bool value) { setBasicSetting("serverChat", value); }
|
|
|
|
void MySettings::setNetworkPort(int value) { setBasicSetting("networkPort", value); }
|
|
|
|
void MySettings::setUserDefaultModel(const QString &value) { setBasicSetting("userDefaultModel", value); }
|
|
|
|
void MySettings::setChatTheme(const QString &value) { setBasicSetting("chatTheme", value); }
|
|
|
|
void MySettings::setFontSize(const QString &value) { setBasicSetting("fontSize", value); }
|
|
|
|
void MySettings::setLastVersionStarted(const QString &value) { setBasicSetting("lastVersionStarted", value); }
|
|
|
|
void MySettings::setLocalDocsChunkSize(int value) { setBasicSetting("localdocs/chunkSize", value, "localDocsChunkSize"); }
|
|
|
|
void MySettings::setLocalDocsRetrievalSize(int value) { setBasicSetting("localdocs/retrievalSize", value, "localDocsRetrievalSize"); }
|
|
|
|
void MySettings::setLocalDocsShowReferences(bool value) { setBasicSetting("localdocs/showReferences", value, "localDocsShowReferences"); }
|
|
|
|
void MySettings::setLocalDocsFileExtensions(const QStringList &value) { setBasicSetting("localdocs/fileExtensions", value, "localDocsFileExtensions"); }
|
|
|
|
void MySettings::setLocalDocsUseRemoteEmbed(bool value) { setBasicSetting("localdocs/useRemoteEmbed", value, "localDocsUseRemoteEmbed"); }
|
|
|
|
void MySettings::setLocalDocsNomicAPIKey(const QString &value) { setBasicSetting("localdocs/nomicAPIKey", value, "localDocsNomicAPIKey"); }
|
2024-06-28 12:57:57 -04:00
|
|
|
void MySettings::setLocalDocsEmbedDevice(const QString &value) { setBasicSetting("localdocs/embedDevice", value, "localDocsEmbedDevice"); }
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setNetworkAttribution(const QString &value) { setBasicSetting("network/attribution", value, "networkAttribution"); }
|
|
|
|
|
|
|
|
QString MySettings::modelPath()
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-09 11:50:44 -04:00
|
|
|
// We have to migrate the old setting because I changed the setting key recklessly in v2.4.11
|
|
|
|
// which broke a lot of existing installs
|
2024-06-24 18:49:23 -04:00
|
|
|
const bool containsOldSetting = m_settings.contains("modelPaths");
|
2023-07-09 11:50:44 -04:00
|
|
|
if (containsOldSetting) {
|
2024-06-24 18:49:23 -04:00
|
|
|
const bool containsNewSetting = m_settings.contains("modelPath");
|
2023-07-09 11:50:44 -04:00
|
|
|
if (!containsNewSetting)
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.setValue("modelPath", m_settings.value("modelPaths"));
|
|
|
|
m_settings.remove("modelPaths");
|
2023-07-09 11:50:44 -04:00
|
|
|
}
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value("modelPath", defaultLocalModelsPath()).toString();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setModelPath(const QString &value)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
QString filePath = (value.startsWith("file://") ?
|
|
|
|
QUrl(value).toLocalFile() : value);
|
2023-06-28 16:05:35 -04:00
|
|
|
QString canonical = QFileInfo(filePath).canonicalFilePath() + "/";
|
|
|
|
if (modelPath() == canonical)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.setValue("modelPath", canonical);
|
2023-06-28 13:47:57 -04:00
|
|
|
emit modelPathChanged();
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
QString MySettings::device()
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
auto value = m_settings.value("device");
|
2024-05-15 15:27:50 -04:00
|
|
|
if (!value.isValid())
|
2024-06-24 18:49:23 -04:00
|
|
|
return defaults::device;
|
2024-05-15 15:27:50 -04:00
|
|
|
|
|
|
|
auto device = value.toString();
|
|
|
|
if (!device.isEmpty()) {
|
|
|
|
auto deviceStr = device.toStdString();
|
|
|
|
auto newNameStr = LLModel::GPUDevice::updateSelectionName(deviceStr);
|
|
|
|
if (newNameStr != deviceStr) {
|
|
|
|
auto newName = QString::fromStdString(newNameStr);
|
|
|
|
qWarning() << "updating device name:" << device << "->" << newName;
|
|
|
|
device = newName;
|
2024-06-24 18:49:23 -04:00
|
|
|
m_settings.setValue("device", device);
|
2024-05-15 15:27:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return device;
|
2023-09-13 10:32:08 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setDevice(const QString &value)
|
2023-09-13 10:32:08 -04:00
|
|
|
{
|
2024-06-28 12:57:57 -04:00
|
|
|
if (device() != value) {
|
|
|
|
m_settings.setValue("device", value);
|
|
|
|
emit deviceChanged();
|
|
|
|
}
|
2023-09-13 10:32:08 -04:00
|
|
|
}
|
|
|
|
|
2023-06-27 11:54:34 -04:00
|
|
|
bool MySettings::forceMetal() const
|
|
|
|
{
|
|
|
|
return m_forceMetal;
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setForceMetal(bool value)
|
2023-06-28 20:42:40 -04:00
|
|
|
{
|
2024-06-28 12:57:57 -04:00
|
|
|
if (m_forceMetal != value) {
|
|
|
|
m_forceMetal = value;
|
|
|
|
emit forceMetalChanged(value);
|
|
|
|
}
|
2023-06-28 20:42:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::networkIsActive() const
|
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value("network/isActive", defaults::networkIsActive).toBool();
|
2023-06-28 20:42:40 -04:00
|
|
|
}
|
|
|
|
|
2024-04-25 13:16:52 -04:00
|
|
|
bool MySettings::isNetworkIsActiveSet() const
|
2023-06-28 20:42:40 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value("network/isActive").isValid();
|
2024-04-25 13:16:52 -04:00
|
|
|
}
|
2023-06-28 20:42:40 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setNetworkIsActive(bool value)
|
2024-04-25 13:16:52 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
auto cur = m_settings.value("network/isActive");
|
|
|
|
if (!cur.isValid() || cur.toBool() != value) {
|
|
|
|
m_settings.setValue("network/isActive", value);
|
2024-04-25 13:16:52 -04:00
|
|
|
emit networkIsActiveChanged();
|
|
|
|
}
|
2023-06-28 20:42:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::networkUsageStatsActive() const
|
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value("network/usageStatsActive", defaults::networkUsageStatsActive).toBool();
|
2023-06-28 20:42:40 -04:00
|
|
|
}
|
|
|
|
|
2024-04-25 13:16:52 -04:00
|
|
|
bool MySettings::isNetworkUsageStatsActiveSet() const
|
2023-06-28 20:42:40 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
return m_settings.value("network/usageStatsActive").isValid();
|
2024-04-25 13:16:52 -04:00
|
|
|
}
|
2023-06-28 20:42:40 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
void MySettings::setNetworkUsageStatsActive(bool value)
|
2024-04-25 13:16:52 -04:00
|
|
|
{
|
2024-06-24 18:49:23 -04:00
|
|
|
auto cur = m_settings.value("network/usageStatsActive");
|
|
|
|
if (!cur.isValid() || cur.toBool() != value) {
|
|
|
|
m_settings.setValue("network/usageStatsActive", value);
|
2024-04-25 13:16:52 -04:00
|
|
|
emit networkUsageStatsActiveChanged();
|
|
|
|
}
|
2023-06-28 20:42:40 -04:00
|
|
|
}
|