2023-06-27 11:54:34 -04:00
|
|
|
#include "mysettings.h"
|
2023-07-01 11:34:21 -04:00
|
|
|
#include "modellist.h"
|
2023-09-15 14:45:25 -04:00
|
|
|
#include "../gpt4all-backend/llmodel.h"
|
2023-06-27 11:54:34 -04:00
|
|
|
|
2023-06-28 13:47:57 -04:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
2023-06-27 11:54:34 -04:00
|
|
|
#include <QSettings>
|
2023-06-28 13:47:57 -04:00
|
|
|
#include <QStandardPaths>
|
2023-06-28 16:05:35 -04:00
|
|
|
#include <QUrl>
|
2023-06-28 13:47:57 -04:00
|
|
|
|
2023-07-10 16:52:32 -04:00
|
|
|
static int default_threadCount = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
2023-10-11 10:23:33 -04:00
|
|
|
static bool default_saveChatsContext = false;
|
2023-06-28 13:47:57 -04:00
|
|
|
static bool default_serverChat = false;
|
|
|
|
static QString default_userDefaultModel = "Application default";
|
|
|
|
static bool default_forceMetal = false;
|
2023-06-28 20:42:40 -04:00
|
|
|
static QString default_lastVersionStarted = "";
|
|
|
|
static int default_localDocsChunkSize = 256;
|
2023-07-26 15:42:07 -04:00
|
|
|
static QString default_chatTheme = "Dark";
|
2023-08-07 13:54:13 -04:00
|
|
|
static QString default_fontSize = "Small";
|
2023-06-28 20:42:40 -04:00
|
|
|
static int default_localDocsRetrievalSize = 3;
|
2023-07-05 19:41:07 -04:00
|
|
|
static bool default_localDocsShowReferences = true;
|
2023-06-28 20:42:40 -04:00
|
|
|
static QString default_networkAttribution = "";
|
|
|
|
static bool default_networkIsActive = false;
|
|
|
|
static bool default_networkUsageStatsActive = false;
|
2023-09-13 10:32:08 -04:00
|
|
|
static QString default_device = "Auto";
|
2023-06-28 13:47:57 -04:00
|
|
|
|
|
|
|
static QString defaultLocalModelsPath()
|
|
|
|
{
|
|
|
|
QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
|
|
|
|
+ "/";
|
|
|
|
QString testWritePath = localPath + QString("test_write.txt");
|
|
|
|
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
|
|
|
|
|
|
|
class MyPrivateSettings: public MySettings { };
|
|
|
|
Q_GLOBAL_STATIC(MyPrivateSettings, settingsInstance)
|
|
|
|
MySettings *MySettings::globalInstance()
|
|
|
|
{
|
|
|
|
return settingsInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
MySettings::MySettings()
|
|
|
|
: QObject{nullptr}
|
|
|
|
{
|
2023-06-28 13:47:57 -04:00
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
2023-09-15 14:45:25 -04:00
|
|
|
|
2023-12-13 12:11:09 -05:00
|
|
|
std::vector<LLModel::GPUDevice> devices = LLModel::Implementation::availableGPUDevices();
|
2023-09-15 14:45:25 -04:00
|
|
|
QVector<QString> deviceList{ "Auto" };
|
|
|
|
for (LLModel::GPUDevice &d : devices)
|
|
|
|
deviceList << QString::fromStdString(d.name);
|
|
|
|
deviceList << "CPU";
|
|
|
|
setDeviceList(deviceList);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-09-13 10:32:08 -04:00
|
|
|
Q_INVOKABLE QVector<QString> MySettings::deviceList() const
|
|
|
|
{
|
|
|
|
return m_deviceList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setDeviceList(const QVector<QString> &deviceList)
|
|
|
|
{
|
|
|
|
m_deviceList = deviceList;
|
|
|
|
emit deviceListChanged();
|
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::restoreModelDefaults(const ModelInfo &model)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
setModelTemperature(model, model.m_temperature);
|
|
|
|
setModelTopP(model, model.m_topP);
|
|
|
|
setModelTopK(model, model.m_topK);;
|
|
|
|
setModelMaxLength(model, model.m_maxLength);
|
|
|
|
setModelPromptBatchSize(model, model.m_promptBatchSize);
|
2023-12-16 17:58:15 -05:00
|
|
|
setModelContextLength(model, model.m_contextLength);
|
2024-01-31 14:17:44 -05:00
|
|
|
setModelGpuLayers(model, model.m_gpuLayers);
|
2023-07-01 11:34:21 -04:00
|
|
|
setModelRepeatPenalty(model, model.m_repeatPenalty);
|
|
|
|
setModelRepeatPenaltyTokens(model, model.m_repeatPenaltyTokens);
|
|
|
|
setModelPromptTemplate(model, model.m_promptTemplate);
|
|
|
|
setModelSystemPrompt(model, model.m_systemPrompt);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::restoreApplicationDefaults()
|
|
|
|
{
|
2023-09-13 10:32:08 -04:00
|
|
|
setChatTheme(default_chatTheme);
|
|
|
|
setFontSize(default_fontSize);
|
|
|
|
setDevice(default_device);
|
2023-06-28 13:47:57 -04:00
|
|
|
setThreadCount(default_threadCount);
|
2023-10-11 10:23:33 -04:00
|
|
|
setSaveChatsContext(default_saveChatsContext);
|
2023-06-28 13:47:57 -04:00
|
|
|
setServerChat(default_serverChat);
|
|
|
|
setModelPath(defaultLocalModelsPath());
|
|
|
|
setUserDefaultModel(default_userDefaultModel);
|
|
|
|
setForceMetal(default_forceMetal);
|
|
|
|
}
|
|
|
|
|
2023-06-28 20:42:40 -04:00
|
|
|
void MySettings::restoreLocalDocsDefaults()
|
|
|
|
{
|
|
|
|
setLocalDocsChunkSize(default_localDocsChunkSize);
|
|
|
|
setLocalDocsRetrievalSize(default_localDocsRetrievalSize);
|
2023-07-05 19:41:07 -04:00
|
|
|
setLocalDocsShowReferences(default_localDocsShowReferences);
|
2023-06-28 20:42:40 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::eraseModel(const ModelInfo &m)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.remove(QString("model-%1").arg(m.id()));
|
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MySettings::modelName(const ModelInfo &m) const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/name",
|
|
|
|
!m.m_name.isEmpty() ? m.m_name : m.m_filename).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelName(const ModelInfo &m, const QString &name, bool force)
|
|
|
|
{
|
|
|
|
if ((modelName(m) == name || m.id().isEmpty()) && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
if ((m.m_name == name || m.m_filename == name) && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/name");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/name", name);
|
|
|
|
if (m.isClone)
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/isClone", "true");
|
|
|
|
setting.sync();
|
|
|
|
if (!force)
|
|
|
|
emit nameChanged(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MySettings::modelFilename(const ModelInfo &m) const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/filename", m.m_filename).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelFilename(const ModelInfo &m, const QString &filename, bool force)
|
|
|
|
{
|
|
|
|
if ((modelFilename(m) == filename || m.id().isEmpty()) && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
if (m.m_filename == filename && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/filename");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/filename", filename);
|
|
|
|
setting.sync();
|
|
|
|
if (!force)
|
|
|
|
emit filenameChanged(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
double MySettings::modelTemperature(const ModelInfo &m) const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/temperature", m.m_temperature).toDouble();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelTemperature(const ModelInfo &m, double t, bool force)
|
|
|
|
{
|
|
|
|
if (modelTemperature(m) == t && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
if (m.m_temperature == t && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/temperature");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/temperature", t);
|
|
|
|
setting.sync();
|
|
|
|
if (!force)
|
|
|
|
emit temperatureChanged(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
double MySettings::modelTopP(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/topP", m.m_topP).toDouble();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelTopP(const ModelInfo &m, double p, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelTopP(m) == p && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_topP == p && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/topP");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/topP", p);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit topPChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
int MySettings::modelTopK(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/topK", m.m_topK).toInt();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelTopK(const ModelInfo &m, int k, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelTopK(m) == k && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_topK == k && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/topK");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/topK", k);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit topKChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
int MySettings::modelMaxLength(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/maxLength", m.m_maxLength).toInt();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelMaxLength(const ModelInfo &m, int l, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelMaxLength(m) == l && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_maxLength == l && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/maxLength");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/maxLength", l);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit maxLengthChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
int MySettings::modelPromptBatchSize(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/promptBatchSize", m.m_promptBatchSize).toInt();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelPromptBatchSize(const ModelInfo &m, int s, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelPromptBatchSize(m) == s && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_promptBatchSize == s && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/promptBatchSize");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/promptBatchSize", s);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit promptBatchSizeChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-12-16 17:58:15 -05:00
|
|
|
int MySettings::modelContextLength(const ModelInfo &m) const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/contextLength", m.m_contextLength).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelContextLength(const ModelInfo &m, int l, bool force)
|
|
|
|
{
|
|
|
|
if (modelContextLength(m) == l && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
if (m.m_contextLength == l && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/contextLength");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/contextLength", l);
|
|
|
|
setting.sync();
|
|
|
|
if (!force)
|
|
|
|
emit contextLengthChanged(m);
|
|
|
|
}
|
|
|
|
|
2024-01-31 14:17:44 -05:00
|
|
|
int MySettings::modelGpuLayers(const ModelInfo &m) const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/gpuLayers", m.m_gpuLayers).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelGpuLayers(const ModelInfo &m, int l, bool force)
|
|
|
|
{
|
|
|
|
if (modelGpuLayers(m) == l && !force)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
if (m.m_gpuLayers == l && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/gpuLayers");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/gpuLayers", l);
|
|
|
|
setting.sync();
|
|
|
|
if (!force)
|
|
|
|
emit gpuLayersChanged(m);
|
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
double MySettings::modelRepeatPenalty(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/repeatPenalty", m.m_repeatPenalty).toDouble();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelRepeatPenalty(const ModelInfo &m, double p, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelRepeatPenalty(m) == p && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_repeatPenalty == p && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/repeatPenalty");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/repeatPenalty", p);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit repeatPenaltyChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
int MySettings::modelRepeatPenaltyTokens(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/repeatPenaltyTokens", m.m_repeatPenaltyTokens).toInt();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelRepeatPenaltyTokens(const ModelInfo &m, int t, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelRepeatPenaltyTokens(m) == t && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_repeatPenaltyTokens == t && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/repeatPenaltyTokens");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/repeatPenaltyTokens", t);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit repeatPenaltyTokensChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
QString MySettings::modelPromptTemplate(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/promptTemplate", m.m_promptTemplate).toString();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelPromptTemplate(const ModelInfo &m, const QString &t, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelPromptTemplate(m) == t && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_promptTemplate == t && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/promptTemplate");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/promptTemplate", t);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit promptTemplateChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
QString MySettings::modelSystemPrompt(const ModelInfo &m) const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/systemPrompt", m.m_systemPrompt).toString();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-01 11:34:21 -04:00
|
|
|
void MySettings::setModelSystemPrompt(const ModelInfo &m, const QString &p, bool force)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-07-01 11:34:21 -04:00
|
|
|
if (modelSystemPrompt(m) == p && !force)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 11:34:21 -04:00
|
|
|
if (m.m_systemPrompt == p && !m.isClone)
|
|
|
|
setting.remove(QString("model-%1").arg(m.id()) + "/systemPrompt");
|
|
|
|
else
|
|
|
|
setting.setValue(QString("model-%1").arg(m.id()) + "/systemPrompt", p);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-07-01 11:34:21 -04:00
|
|
|
if (!force)
|
|
|
|
emit systemPromptChanged(m);
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int MySettings::threadCount() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-10 16:52:32 -04:00
|
|
|
int c = setting.value("threadCount", default_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)
|
|
|
|
c = default_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
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setThreadCount(int c)
|
|
|
|
{
|
|
|
|
if (threadCount() == c)
|
|
|
|
return;
|
|
|
|
|
2023-07-10 16:52:32 -04:00
|
|
|
c = std::max(c, 1);
|
|
|
|
c = std::min(c, QThread::idealThreadCount());
|
2023-06-28 13:47:57 -04:00
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("threadCount", c);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-06-28 13:47:57 -04:00
|
|
|
emit threadCountChanged();
|
|
|
|
}
|
|
|
|
|
2023-10-11 10:23:33 -04:00
|
|
|
bool MySettings::saveChatsContext() const
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-10-11 10:23:33 -04:00
|
|
|
return setting.value("saveChatsContext", default_saveChatsContext).toBool();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
2023-10-11 10:23:33 -04:00
|
|
|
void MySettings::setSaveChatsContext(bool b)
|
2023-06-28 13:47:57 -04:00
|
|
|
{
|
2023-10-11 10:23:33 -04:00
|
|
|
if (saveChatsContext() == b)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-10-11 10:23:33 -04:00
|
|
|
setting.setValue("saveChatsContext", b);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-10-11 10:23:33 -04:00
|
|
|
emit saveChatsContextChanged();
|
2023-06-28 13:47:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::serverChat() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("serverChat", default_serverChat).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setServerChat(bool b)
|
|
|
|
{
|
|
|
|
if (serverChat() == b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("serverChat", b);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-06-28 13:47:57 -04:00
|
|
|
emit serverChatChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MySettings::modelPath() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
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
|
|
|
|
const bool containsOldSetting = setting.contains("modelPaths");
|
|
|
|
if (containsOldSetting) {
|
|
|
|
const bool containsNewSetting = setting.contains("modelPath");
|
|
|
|
if (!containsNewSetting)
|
|
|
|
setting.setValue("modelPath", setting.value("modelPaths"));
|
|
|
|
setting.remove("modelPaths");
|
|
|
|
setting.sync();
|
|
|
|
}
|
2023-06-28 13:47:57 -04:00
|
|
|
return setting.value("modelPath", defaultLocalModelsPath()).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelPath(const QString &p)
|
|
|
|
{
|
2023-06-28 16:05:35 -04:00
|
|
|
QString filePath = (p.startsWith("file://") ?
|
|
|
|
QUrl(p).toLocalFile() : p);
|
|
|
|
QString canonical = QFileInfo(filePath).canonicalFilePath() + "/";
|
|
|
|
if (modelPath() == canonical)
|
2023-06-28 13:47:57 -04:00
|
|
|
return;
|
|
|
|
QSettings setting;
|
2023-06-28 16:05:35 -04:00
|
|
|
setting.setValue("modelPath", canonical);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-06-28 13:47:57 -04:00
|
|
|
emit modelPathChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MySettings::userDefaultModel() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("userDefaultModel", default_userDefaultModel).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setUserDefaultModel(const QString &u)
|
|
|
|
{
|
|
|
|
if (userDefaultModel() == u)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("userDefaultModel", u);
|
2023-06-28 13:59:18 -04:00
|
|
|
setting.sync();
|
2023-06-28 13:47:57 -04:00
|
|
|
emit userDefaultModelChanged();
|
2023-06-27 11:54:34 -04:00
|
|
|
}
|
|
|
|
|
2023-07-26 15:42:07 -04:00
|
|
|
QString MySettings::chatTheme() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("chatTheme", default_chatTheme).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setChatTheme(const QString &u)
|
|
|
|
{
|
2023-09-13 10:32:08 -04:00
|
|
|
if (chatTheme() == u)
|
2023-07-26 15:42:07 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("chatTheme", u);
|
|
|
|
setting.sync();
|
|
|
|
emit chatThemeChanged();
|
|
|
|
}
|
|
|
|
|
2023-08-07 13:54:13 -04:00
|
|
|
QString MySettings::fontSize() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("fontSize", default_fontSize).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setFontSize(const QString &u)
|
|
|
|
{
|
2023-09-13 10:32:08 -04:00
|
|
|
if (fontSize() == u)
|
2023-08-07 13:54:13 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("fontSize", u);
|
|
|
|
setting.sync();
|
|
|
|
emit fontSizeChanged();
|
|
|
|
}
|
|
|
|
|
2023-09-13 10:32:08 -04:00
|
|
|
QString MySettings::device() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("device", default_device).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setDevice(const QString &u)
|
|
|
|
{
|
|
|
|
if (device() == u)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("device", u);
|
|
|
|
setting.sync();
|
|
|
|
emit deviceChanged();
|
|
|
|
}
|
|
|
|
|
2023-06-27 11:54:34 -04:00
|
|
|
bool MySettings::forceMetal() const
|
|
|
|
{
|
|
|
|
return m_forceMetal;
|
|
|
|
}
|
|
|
|
|
2023-06-28 13:47:57 -04:00
|
|
|
void MySettings::setForceMetal(bool b)
|
2023-06-27 11:54:34 -04:00
|
|
|
{
|
2023-06-28 13:47:57 -04:00
|
|
|
if (m_forceMetal == b)
|
2023-06-27 11:54:34 -04:00
|
|
|
return;
|
2023-06-28 13:47:57 -04:00
|
|
|
m_forceMetal = b;
|
|
|
|
emit forceMetalChanged(b);
|
2023-06-27 11:54:34 -04:00
|
|
|
}
|
2023-06-28 20:42:40 -04:00
|
|
|
|
|
|
|
QString MySettings::lastVersionStarted() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("lastVersionStarted", default_lastVersionStarted).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setLastVersionStarted(const QString &v)
|
|
|
|
{
|
|
|
|
if (lastVersionStarted() == v)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("lastVersionStarted", v);
|
|
|
|
setting.sync();
|
|
|
|
emit lastVersionStartedChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MySettings::localDocsChunkSize() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("localdocs/chunkSize", default_localDocsChunkSize).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setLocalDocsChunkSize(int s)
|
|
|
|
{
|
|
|
|
if (localDocsChunkSize() == s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("localdocs/chunkSize", s);
|
|
|
|
setting.sync();
|
|
|
|
emit localDocsChunkSizeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MySettings::localDocsRetrievalSize() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("localdocs/retrievalSize", default_localDocsRetrievalSize).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setLocalDocsRetrievalSize(int s)
|
|
|
|
{
|
|
|
|
if (localDocsRetrievalSize() == s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("localdocs/retrievalSize", s);
|
|
|
|
setting.sync();
|
|
|
|
emit localDocsRetrievalSizeChanged();
|
|
|
|
}
|
|
|
|
|
2023-07-05 19:41:07 -04:00
|
|
|
bool MySettings::localDocsShowReferences() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("localdocs/showReferences", default_localDocsShowReferences).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setLocalDocsShowReferences(bool b)
|
|
|
|
{
|
|
|
|
if (localDocsShowReferences() == b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("localdocs/showReferences", b);
|
|
|
|
setting.sync();
|
|
|
|
emit localDocsShowReferencesChanged();
|
|
|
|
}
|
|
|
|
|
2023-06-28 20:42:40 -04:00
|
|
|
QString MySettings::networkAttribution() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("network/attribution", default_networkAttribution).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setNetworkAttribution(const QString &a)
|
|
|
|
{
|
|
|
|
if (networkAttribution() == a)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("network/attribution", a);
|
|
|
|
setting.sync();
|
|
|
|
emit networkAttributionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::networkIsActive() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("network/isActive", default_networkIsActive).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setNetworkIsActive(bool b)
|
|
|
|
{
|
|
|
|
if (networkIsActive() == b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("network/isActive", b);
|
|
|
|
setting.sync();
|
|
|
|
emit networkIsActiveChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::networkUsageStatsActive() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("network/usageStatsActive", default_networkUsageStatsActive).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setNetworkUsageStatsActive(bool b)
|
|
|
|
{
|
|
|
|
if (networkUsageStatsActive() == b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("network/usageStatsActive", b);
|
|
|
|
setting.sync();
|
|
|
|
emit networkUsageStatsActiveChanged();
|
|
|
|
}
|
2023-07-11 12:09:33 -04:00
|
|
|
|
|
|
|
QString MySettings::attemptModelLoad() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("attemptModelLoad", QString()).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setAttemptModelLoad(const QString &modelFile)
|
|
|
|
{
|
|
|
|
if (attemptModelLoad() == modelFile)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
if (modelFile.isEmpty())
|
|
|
|
setting.remove("attemptModelLoad");
|
|
|
|
else
|
|
|
|
setting.setValue("attemptModelLoad", modelFile);
|
|
|
|
setting.sync();
|
|
|
|
emit attemptModelLoadChanged();
|
|
|
|
}
|