gpt4all/gpt4all-chat/mysettings.h

214 lines
10 KiB
C
Raw Normal View History

2023-06-27 11:54:34 -04:00
#ifndef MYSETTINGS_H
#define MYSETTINGS_H
#include "modellist.h" // IWYU pragma: keep
#include <QDateTime>
2023-06-27 11:54:34 -04:00
#include <QObject>
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QVector>
2023-06-27 11:54:34 -04:00
#include <cstdint>
#include <optional>
2023-06-27 11:54:34 -04:00
class MySettings : public QObject
{
Q_OBJECT
Q_PROPERTY(int threadCount READ threadCount WRITE setThreadCount NOTIFY threadCountChanged)
Q_PROPERTY(bool saveChatsContext READ saveChatsContext WRITE setSaveChatsContext NOTIFY saveChatsContextChanged)
Q_PROPERTY(bool serverChat READ serverChat WRITE setServerChat NOTIFY serverChatChanged)
Q_PROPERTY(QString modelPath READ modelPath WRITE setModelPath NOTIFY modelPathChanged)
Q_PROPERTY(QString userDefaultModel READ userDefaultModel WRITE setUserDefaultModel NOTIFY userDefaultModelChanged)
2023-07-26 15:42:07 -04:00
Q_PROPERTY(QString chatTheme READ chatTheme WRITE setChatTheme NOTIFY chatThemeChanged)
2023-08-07 13:54:13 -04:00
Q_PROPERTY(QString fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
2023-06-27 11:54:34 -04:00
Q_PROPERTY(bool forceMetal READ forceMetal WRITE setForceMetal NOTIFY forceMetalChanged)
Q_PROPERTY(QString lastVersionStarted READ lastVersionStarted WRITE setLastVersionStarted NOTIFY lastVersionStartedChanged)
Q_PROPERTY(int localDocsChunkSize READ localDocsChunkSize WRITE setLocalDocsChunkSize NOTIFY localDocsChunkSizeChanged)
Q_PROPERTY(int localDocsRetrievalSize READ localDocsRetrievalSize WRITE setLocalDocsRetrievalSize NOTIFY localDocsRetrievalSizeChanged)
Q_PROPERTY(bool localDocsShowReferences READ localDocsShowReferences WRITE setLocalDocsShowReferences NOTIFY localDocsShowReferencesChanged)
Q_PROPERTY(QStringList localDocsFileExtensions READ localDocsFileExtensions WRITE setLocalDocsFileExtensions NOTIFY localDocsFileExtensionsChanged)
Q_PROPERTY(bool localDocsUseRemoteEmbed READ localDocsUseRemoteEmbed WRITE setLocalDocsUseRemoteEmbed NOTIFY localDocsUseRemoteEmbedChanged)
Q_PROPERTY(QString localDocsNomicAPIKey READ localDocsNomicAPIKey WRITE setLocalDocsNomicAPIKey NOTIFY localDocsNomicAPIKeyChanged)
Q_PROPERTY(QString networkAttribution READ networkAttribution WRITE setNetworkAttribution NOTIFY networkAttributionChanged)
Q_PROPERTY(bool networkIsActive READ networkIsActive WRITE setNetworkIsActive NOTIFY networkIsActiveChanged)
Q_PROPERTY(bool networkUsageStatsActive READ networkUsageStatsActive WRITE setNetworkUsageStatsActive NOTIFY networkUsageStatsActiveChanged)
2023-09-13 10:32:08 -04:00
Q_PROPERTY(QString device READ device WRITE setDevice NOTIFY deviceChanged)
Q_PROPERTY(QVector<QString> deviceList READ deviceList NOTIFY deviceListChanged)
2023-11-11 13:52:51 -05:00
Q_PROPERTY(int networkPort READ networkPort WRITE setNetworkPort NOTIFY networkPortChanged)
2023-06-27 11:54:34 -04:00
public:
static MySettings *globalInstance();
// Restore methods
Q_INVOKABLE void restoreModelDefaults(const ModelInfo &info);
Q_INVOKABLE void restoreApplicationDefaults();
Q_INVOKABLE void restoreLocalDocsDefaults();
// Model/Character settings
void eraseModel(const ModelInfo &info);
QString modelName(const ModelInfo &info) const;
Q_INVOKABLE void setModelName(const ModelInfo &info, const QString &name, bool force = false);
QString modelFilename(const ModelInfo &info) const;
Q_INVOKABLE void setModelFilename(const ModelInfo &info, const QString &filename, bool force = false);
QString modelDescription(const ModelInfo &info) const;
void setModelDescription(const ModelInfo &info, const QString &value, bool force = false);
QString modelUrl(const ModelInfo &info) const;
void setModelUrl(const ModelInfo &info, const QString &value, bool force = false);
QString modelQuant(const ModelInfo &info) const;
void setModelQuant(const ModelInfo &info, const QString &value, bool force = false);
QString modelType(const ModelInfo &info) const;
void setModelType(const ModelInfo &info, const QString &value, bool force = false);
bool modelIsClone(const ModelInfo &info) const;
void setModelIsClone(const ModelInfo &info, bool value, bool force = false);
bool modelIsDiscovered(const ModelInfo &info) const;
void setModelIsDiscovered(const ModelInfo &info, bool value, bool force = false);
int modelLikes(const ModelInfo &info) const;
void setModelLikes(const ModelInfo &info, int value, bool force = false);
int modelDownloads(const ModelInfo &info) const;
void setModelDownloads(const ModelInfo &info, int value, bool force = false);
QDateTime modelRecency(const ModelInfo &info) const;
void setModelRecency(const ModelInfo &info, const QDateTime &value, bool force = false);
double modelTemperature(const ModelInfo &info) const;
Q_INVOKABLE void setModelTemperature(const ModelInfo &info, double value, bool force = false);
double modelTopP(const ModelInfo &info) const;
Q_INVOKABLE void setModelTopP(const ModelInfo &info, double value, bool force = false);
double modelMinP(const ModelInfo &info) const;
Q_INVOKABLE void setModelMinP(const ModelInfo &info, double value, bool force = false);
int modelTopK(const ModelInfo &info) const;
Q_INVOKABLE void setModelTopK(const ModelInfo &info, int value, bool force = false);
int modelMaxLength(const ModelInfo &info) const;
Q_INVOKABLE void setModelMaxLength(const ModelInfo &info, int value, bool force = false);
int modelPromptBatchSize(const ModelInfo &info) const;
Q_INVOKABLE void setModelPromptBatchSize(const ModelInfo &info, int value, bool force = false);
double modelRepeatPenalty(const ModelInfo &info) const;
Q_INVOKABLE void setModelRepeatPenalty(const ModelInfo &info, double value, bool force = false);
int modelRepeatPenaltyTokens(const ModelInfo &info) const;
Q_INVOKABLE void setModelRepeatPenaltyTokens(const ModelInfo &info, int value, bool force = false);
QString modelPromptTemplate(const ModelInfo &info) const;
Q_INVOKABLE void setModelPromptTemplate(const ModelInfo &info, const QString &value, bool force = false);
QString modelSystemPrompt(const ModelInfo &info) const;
Q_INVOKABLE void setModelSystemPrompt(const ModelInfo &info, const QString &value, bool force = false);
int modelContextLength(const ModelInfo &info) const;
Q_INVOKABLE void setModelContextLength(const ModelInfo &info, int value, bool force = false);
int modelGpuLayers(const ModelInfo &info) const;
Q_INVOKABLE void setModelGpuLayers(const ModelInfo &info, int value, bool force = false);
// Application settings
int threadCount() const;
void setThreadCount(int value);
bool saveChatsContext() const;
void setSaveChatsContext(bool value);
bool serverChat() const;
void setServerChat(bool value);
QString modelPath();
void setModelPath(const QString &value);
QString userDefaultModel() const;
void setUserDefaultModel(const QString &value);
2023-07-26 15:42:07 -04:00
QString chatTheme() const;
void setChatTheme(const QString &value);
2023-08-07 13:54:13 -04:00
QString fontSize() const;
void setFontSize(const QString &value);
2023-06-27 11:54:34 -04:00
bool forceMetal() const;
void setForceMetal(bool value);
QString device();
void setDevice(const QString &value);
int32_t contextLength() const;
void setContextLength(int32_t value);
int32_t gpuLayers() const;
void setGpuLayers(int32_t value);
2023-06-27 11:54:34 -04:00
// Release/Download settings
QString lastVersionStarted() const;
void setLastVersionStarted(const QString &value);
// Localdocs settings
int localDocsChunkSize() const;
void setLocalDocsChunkSize(int value);
int localDocsRetrievalSize() const;
void setLocalDocsRetrievalSize(int value);
bool localDocsShowReferences() const;
void setLocalDocsShowReferences(bool value);
QStringList localDocsFileExtensions() const;
void setLocalDocsFileExtensions(const QStringList &value);
bool localDocsUseRemoteEmbed() const;
void setLocalDocsUseRemoteEmbed(bool value);
QString localDocsNomicAPIKey() const;
void setLocalDocsNomicAPIKey(const QString &value);
// Network settings
QString networkAttribution() const;
void setNetworkAttribution(const QString &value);
bool networkIsActive() const;
Q_INVOKABLE bool isNetworkIsActiveSet() const;
void setNetworkIsActive(bool value);
bool networkUsageStatsActive() const;
Q_INVOKABLE bool isNetworkUsageStatsActiveSet() const;
void setNetworkUsageStatsActive(bool value);
2023-11-11 13:52:51 -05:00
int networkPort() const;
void setNetworkPort(int value);
2023-09-13 10:32:08 -04:00
QVector<QString> deviceList() const;
void setDeviceList(const QVector<QString> &value);
2023-09-13 10:32:08 -04:00
2023-06-27 11:54:34 -04:00
Q_SIGNALS:
void nameChanged(const ModelInfo &info);
void filenameChanged(const ModelInfo &info);
void descriptionChanged(const ModelInfo &info);
void temperatureChanged(const ModelInfo &info);
void topPChanged(const ModelInfo &info);
void minPChanged(const ModelInfo &info);
void topKChanged(const ModelInfo &info);
void maxLengthChanged(const ModelInfo &info);
void promptBatchSizeChanged(const ModelInfo &info);
void contextLengthChanged(const ModelInfo &info);
void gpuLayersChanged(const ModelInfo &info);
void repeatPenaltyChanged(const ModelInfo &info);
void repeatPenaltyTokensChanged(const ModelInfo &info);
void promptTemplateChanged(const ModelInfo &info);
void systemPromptChanged(const ModelInfo &info);
void threadCountChanged();
void saveChatsContextChanged();
void serverChatChanged();
void modelPathChanged();
void userDefaultModelChanged();
2023-07-26 15:42:07 -04:00
void chatThemeChanged();
2023-08-07 13:54:13 -04:00
void fontSizeChanged();
2023-06-27 11:54:34 -04:00
void forceMetalChanged(bool);
void lastVersionStartedChanged();
void localDocsChunkSizeChanged();
void localDocsRetrievalSizeChanged();
void localDocsShowReferencesChanged();
void localDocsFileExtensionsChanged();
void localDocsUseRemoteEmbedChanged();
void localDocsNomicAPIKeyChanged();
void networkAttributionChanged();
void networkIsActiveChanged();
2023-11-11 13:52:51 -05:00
void networkPortChanged();
void networkUsageStatsActiveChanged();
2023-07-11 12:09:33 -04:00
void attemptModelLoadChanged();
2023-09-13 10:32:08 -04:00
void deviceChanged();
void deviceListChanged();
2023-06-27 11:54:34 -04:00
private:
QSettings m_settings;
2023-06-27 11:54:34 -04:00
bool m_forceMetal;
2023-09-13 10:32:08 -04:00
QVector<QString> m_deviceList;
2023-06-27 11:54:34 -04:00
private:
explicit MySettings();
~MySettings() {}
friend class MyPrivateSettings;
QVariant getBasicSetting(const QString &name) const;
void setBasicSetting(const QString &name, const QVariant &value, std::optional<QString> signal = std::nullopt);
QVariant getModelSetting(const QString &name, const ModelInfo &info) const;
void setModelSetting(const QString &name, const ModelInfo &info, const QVariant &value, bool force,
bool signal = false);
2023-06-27 11:54:34 -04:00
};
#endif // MYSETTINGS_H