2023-06-27 15:54:34 +00:00
|
|
|
#include "mysettings.h"
|
2023-07-01 15:34:21 +00:00
|
|
|
#include "modellist.h"
|
2023-06-27 15:54:34 +00:00
|
|
|
|
2023-06-28 17:47:57 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
2023-06-27 15:54:34 +00:00
|
|
|
#include <QSettings>
|
2023-06-28 17:47:57 +00:00
|
|
|
#include <QStandardPaths>
|
2023-06-28 20:05:35 +00:00
|
|
|
#include <QUrl>
|
2023-06-28 17:47:57 +00:00
|
|
|
|
2023-07-10 20:52:32 +00:00
|
|
|
static int default_threadCount = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
2023-06-28 17:47:57 +00:00
|
|
|
static bool default_saveChats = false;
|
|
|
|
static bool default_saveChatGPTChats = true;
|
|
|
|
static bool default_serverChat = false;
|
|
|
|
static QString default_userDefaultModel = "Application default";
|
|
|
|
static bool default_forceMetal = false;
|
2023-06-29 00:42:40 +00:00
|
|
|
static QString default_lastVersionStarted = "";
|
|
|
|
static int default_localDocsChunkSize = 256;
|
|
|
|
static int default_localDocsRetrievalSize = 3;
|
2023-07-05 23:41:07 +00:00
|
|
|
static bool default_localDocsShowReferences = true;
|
2023-06-29 00:42:40 +00:00
|
|
|
static QString default_networkAttribution = "";
|
|
|
|
static bool default_networkIsActive = false;
|
|
|
|
static bool default_networkUsageStatsActive = false;
|
2023-06-28 17:47:57 +00: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 15:54:34 +00:00
|
|
|
|
|
|
|
class MyPrivateSettings: public MySettings { };
|
|
|
|
Q_GLOBAL_STATIC(MyPrivateSettings, settingsInstance)
|
|
|
|
MySettings *MySettings::globalInstance()
|
|
|
|
{
|
|
|
|
return settingsInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
MySettings::MySettings()
|
|
|
|
: QObject{nullptr}
|
|
|
|
{
|
2023-06-28 17:47:57 +00:00
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::restoreModelDefaults(const ModelInfo &model)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00: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);
|
|
|
|
setModelRepeatPenalty(model, model.m_repeatPenalty);
|
|
|
|
setModelRepeatPenaltyTokens(model, model.m_repeatPenaltyTokens);
|
|
|
|
setModelPromptTemplate(model, model.m_promptTemplate);
|
|
|
|
setModelSystemPrompt(model, model.m_systemPrompt);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::restoreApplicationDefaults()
|
|
|
|
{
|
|
|
|
setThreadCount(default_threadCount);
|
|
|
|
setSaveChats(default_saveChats);
|
|
|
|
setSaveChatGPTChats(default_saveChatGPTChats);
|
|
|
|
setServerChat(default_serverChat);
|
|
|
|
setModelPath(defaultLocalModelsPath());
|
|
|
|
setUserDefaultModel(default_userDefaultModel);
|
|
|
|
setForceMetal(default_forceMetal);
|
|
|
|
}
|
|
|
|
|
2023-06-29 00:42:40 +00:00
|
|
|
void MySettings::restoreLocalDocsDefaults()
|
|
|
|
{
|
|
|
|
setLocalDocsChunkSize(default_localDocsChunkSize);
|
|
|
|
setLocalDocsRetrievalSize(default_localDocsRetrievalSize);
|
2023-07-05 23:41:07 +00:00
|
|
|
setLocalDocsShowReferences(default_localDocsShowReferences);
|
2023-06-29 00:42:40 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00: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 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/topP", m.m_topP).toDouble();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelTopP(const ModelInfo &m, double p, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelTopP(m) == p && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit topPChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
int MySettings::modelTopK(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/topK", m.m_topK).toInt();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelTopK(const ModelInfo &m, int k, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelTopK(m) == k && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit topKChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
int MySettings::modelMaxLength(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/maxLength", m.m_maxLength).toInt();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelMaxLength(const ModelInfo &m, int l, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelMaxLength(m) == l && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit maxLengthChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
int MySettings::modelPromptBatchSize(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/promptBatchSize", m.m_promptBatchSize).toInt();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelPromptBatchSize(const ModelInfo &m, int s, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelPromptBatchSize(m) == s && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit promptBatchSizeChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
double MySettings::modelRepeatPenalty(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/repeatPenalty", m.m_repeatPenalty).toDouble();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelRepeatPenalty(const ModelInfo &m, double p, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelRepeatPenalty(m) == p && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit repeatPenaltyChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
int MySettings::modelRepeatPenaltyTokens(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/repeatPenaltyTokens", m.m_repeatPenaltyTokens).toInt();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelRepeatPenaltyTokens(const ModelInfo &m, int t, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelRepeatPenaltyTokens(m) == t && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit repeatPenaltyTokensChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
QString MySettings::modelPromptTemplate(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/promptTemplate", m.m_promptTemplate).toString();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelPromptTemplate(const ModelInfo &m, const QString &t, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelPromptTemplate(m) == t && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit promptTemplateChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
QString MySettings::modelSystemPrompt(const ModelInfo &m) const
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
return setting.value(QString("model-%1").arg(m.id()) + "/systemPrompt", m.m_systemPrompt).toString();
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:34:21 +00:00
|
|
|
void MySettings::setModelSystemPrompt(const ModelInfo &m, const QString &p, bool force)
|
2023-06-28 17:47:57 +00:00
|
|
|
{
|
2023-07-01 15:34:21 +00:00
|
|
|
if (modelSystemPrompt(m) == p && !force)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
2023-07-01 15:34:21 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-07-01 15:34:21 +00:00
|
|
|
if (!force)
|
|
|
|
emit systemPromptChanged(m);
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int MySettings::threadCount() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-10 20:52:32 +00:00
|
|
|
int c = setting.value("threadCount", default_threadCount).toInt();
|
2023-07-11 17:07:15 +00: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 20:52:32 +00:00
|
|
|
c = std::max(c, 1);
|
|
|
|
c = std::min(c, QThread::idealThreadCount());
|
|
|
|
return c;
|
2023-06-28 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setThreadCount(int c)
|
|
|
|
{
|
|
|
|
if (threadCount() == c)
|
|
|
|
return;
|
|
|
|
|
2023-07-10 20:52:32 +00:00
|
|
|
c = std::max(c, 1);
|
|
|
|
c = std::min(c, QThread::idealThreadCount());
|
2023-06-28 17:47:57 +00:00
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("threadCount", c);
|
2023-06-28 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-06-28 17:47:57 +00:00
|
|
|
emit threadCountChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::saveChats() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("saveChats", default_saveChats).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setSaveChats(bool b)
|
|
|
|
{
|
|
|
|
if (saveChats() == b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("saveChats", b);
|
2023-06-28 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-06-28 17:47:57 +00:00
|
|
|
emit saveChatsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::saveChatGPTChats() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
|
|
|
return setting.value("saveChatGPTChats", default_saveChatGPTChats).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setSaveChatGPTChats(bool b)
|
|
|
|
{
|
|
|
|
if (saveChatGPTChats() == b)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
setting.setValue("saveChatGPTChats", b);
|
2023-06-28 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-06-28 17:47:57 +00:00
|
|
|
emit saveChatGPTChatsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-06-28 17:47:57 +00:00
|
|
|
emit serverChatChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MySettings::modelPath() const
|
|
|
|
{
|
|
|
|
QSettings setting;
|
|
|
|
setting.sync();
|
2023-07-09 15:50:44 +00: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 17:47:57 +00:00
|
|
|
return setting.value("modelPath", defaultLocalModelsPath()).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySettings::setModelPath(const QString &p)
|
|
|
|
{
|
2023-06-28 20:05:35 +00:00
|
|
|
QString filePath = (p.startsWith("file://") ?
|
|
|
|
QUrl(p).toLocalFile() : p);
|
|
|
|
QString canonical = QFileInfo(filePath).canonicalFilePath() + "/";
|
|
|
|
if (modelPath() == canonical)
|
2023-06-28 17:47:57 +00:00
|
|
|
return;
|
|
|
|
QSettings setting;
|
2023-06-28 20:05:35 +00:00
|
|
|
setting.setValue("modelPath", canonical);
|
2023-06-28 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-06-28 17:47:57 +00: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 17:59:18 +00:00
|
|
|
setting.sync();
|
2023-06-28 17:47:57 +00:00
|
|
|
emit userDefaultModelChanged();
|
2023-06-27 15:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MySettings::forceMetal() const
|
|
|
|
{
|
|
|
|
return m_forceMetal;
|
|
|
|
}
|
|
|
|
|
2023-06-28 17:47:57 +00:00
|
|
|
void MySettings::setForceMetal(bool b)
|
2023-06-27 15:54:34 +00:00
|
|
|
{
|
2023-06-28 17:47:57 +00:00
|
|
|
if (m_forceMetal == b)
|
2023-06-27 15:54:34 +00:00
|
|
|
return;
|
2023-06-28 17:47:57 +00:00
|
|
|
m_forceMetal = b;
|
|
|
|
emit forceMetalChanged(b);
|
2023-06-27 15:54:34 +00:00
|
|
|
}
|
2023-06-29 00:42:40 +00: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 23:41:07 +00: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-29 00:42:40 +00: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 16:09:33 +00: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();
|
|
|
|
}
|