From 8d2c8c8cb068015239b6ef63d91cbc89a5ef4d9f Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Fri, 5 May 2023 12:30:11 -0400 Subject: [PATCH] Turn off saving chats to disk by default as it eats so much disk space. --- chatlistmodel.cpp | 16 +++++++++++ chatlistmodel.h | 7 +++++ network.cpp | 10 +++++++ network.h | 1 + qml/SettingsDialog.qml | 61 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 94 insertions(+), 1 deletion(-) diff --git a/chatlistmodel.cpp b/chatlistmodel.cpp index fec9c7e4..96c35a64 100644 --- a/chatlistmodel.cpp +++ b/chatlistmodel.cpp @@ -3,6 +3,19 @@ #include #include +bool ChatListModel::shouldSaveChats() const +{ + return m_shouldSaveChats; +} + +void ChatListModel::setShouldSaveChats(bool b) +{ + if (m_shouldSaveChats == b) + return; + m_shouldSaveChats = b; + emit shouldSaveChatsChanged(); +} + void ChatListModel::removeChatFile(Chat *chat) const { QSettings settings; @@ -18,6 +31,9 @@ void ChatListModel::removeChatFile(Chat *chat) const void ChatListModel::saveChats() const { + if (!m_shouldSaveChats) + return; + QSettings settings; QFileInfo settingsInfo(settings.fileName()); QString settingsPath = settingsInfo.absolutePath(); diff --git a/chatlistmodel.h b/chatlistmodel.h index 68633da9..ee28baf1 100644 --- a/chatlistmodel.h +++ b/chatlistmodel.h @@ -9,12 +9,14 @@ class ChatListModel : public QAbstractListModel Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(Chat *currentChat READ currentChat WRITE setCurrentChat NOTIFY currentChatChanged) + Q_PROPERTY(bool shouldSaveChats READ shouldSaveChats WRITE setShouldSaveChats NOTIFY shouldSaveChatsChanged) public: explicit ChatListModel(QObject *parent = nullptr) : QAbstractListModel(parent) , m_currentChat(nullptr) , m_newChat(nullptr) + , m_shouldSaveChats(false) { } @@ -53,6 +55,9 @@ public: return roles; } + bool shouldSaveChats() const; + void setShouldSaveChats(bool b); + Q_INVOKABLE void addChat() { // Don't add a new chat if we already have one @@ -165,6 +170,7 @@ Q_SIGNALS: void connectChat(Chat*); void disconnectChat(Chat*); void currentChatChanged(); + void shouldSaveChatsChanged(); private Q_SLOTS: void newChatCountChanged() @@ -198,6 +204,7 @@ private Q_SLOTS: } private: + bool m_shouldSaveChats; Chat* m_newChat; Chat* m_currentChat; QList m_chats; diff --git a/network.cpp b/network.cpp index ce77419e..8cc06e40 100644 --- a/network.cpp +++ b/network.cpp @@ -306,6 +306,16 @@ void Network::sendNetworkToggled(bool isActive) sendMixpanelEvent("network_toggled", QVector{kv}); } +void Network::sendSaveChatsToggled(bool isActive) +{ + if (!m_usageStatsActive) + return; + KeyValue kv; + kv.key = QString("isActive"); + kv.value = QJsonValue(isActive); + sendMixpanelEvent("savechats_toggled", QVector{kv}); +} + void Network::sendNewChat(int count) { if (!m_usageStatsActive) diff --git a/network.h b/network.h index ddab64e2..eee888f3 100644 --- a/network.h +++ b/network.h @@ -47,6 +47,7 @@ public Q_SLOTS: void sendDownloadFinished(const QString &model, bool success); Q_INVOKABLE void sendSettingsDialog(); Q_INVOKABLE void sendNetworkToggled(bool active); + Q_INVOKABLE void sendSaveChatsToggled(bool active); Q_INVOKABLE void sendNewChat(int count); Q_INVOKABLE void sendRemoveChat(); Q_INVOKABLE void sendRenameChat(); diff --git a/qml/SettingsDialog.qml b/qml/SettingsDialog.qml index 92906dd1..a2a0c62a 100644 --- a/qml/SettingsDialog.qml +++ b/qml/SettingsDialog.qml @@ -37,6 +37,7 @@ Dialog { property real defaultRepeatPenalty: 1.10 property int defaultRepeatPenaltyTokens: 64 property int defaultThreadCount: 0 + property bool defaultSaveChats: false property string defaultPromptTemplate: "### Human: %1 ### Assistant:\n" @@ -51,6 +52,7 @@ Dialog { property alias repeatPenalty: settings.repeatPenalty property alias repeatPenaltyTokens: settings.repeatPenaltyTokens property alias threadCount: settings.threadCount + property alias saveChats: settings.saveChats property alias modelPath: settings.modelPath Settings { @@ -61,6 +63,7 @@ Dialog { property int maxLength: settingsDialog.defaultMaxLength property int promptBatchSize: settingsDialog.defaultPromptBatchSize property int threadCount: settingsDialog.defaultThreadCount + property bool saveChats: settingsDialog.defaultSaveChats property real repeatPenalty: settingsDialog.defaultRepeatPenalty property int repeatPenaltyTokens: settingsDialog.defaultRepeatPenaltyTokens property string promptTemplate: settingsDialog.defaultPromptTemplate @@ -80,13 +83,16 @@ Dialog { function restoreApplicationDefaults() { settings.modelPath = settingsDialog.defaultModelPath settings.threadCount = defaultThreadCount + settings.saveChats = defaultSaveChats Download.downloadLocalModelsPath = settings.modelPath LLM.threadCount = settings.threadCount + LLM.chatListModel.shouldSaveChats = settings.saveChats settings.sync() } Component.onCompleted: { LLM.threadCount = settings.threadCount + LLM.chatListModel.shouldSaveChats = settings.saveChats Download.downloadLocalModelsPath = settings.modelPath } @@ -630,8 +636,61 @@ Dialog { Accessible.name: nThreadsLabel.text Accessible.description: ToolTip.text } - Button { + Label { + id: saveChatsLabel + text: qsTr("Save chats to disk:") + color: theme.textColor Layout.row: 3 + Layout.column: 0 + } + CheckBox { + id: saveChatsBox + Layout.row: 3 + Layout.column: 1 + checked: settingsDialog.saveChats + onClicked: { + Network.sendSaveChatsToggled(saveChatsBox.checked); + settingsDialog.saveChats = saveChatsBox.checked + LLM.chatListModel.shouldSaveChats = saveChatsBox.checked + settings.sync() + } + + ToolTip.text: qsTr("WARNING: Saving chats to disk can be ~2GB per chat") + ToolTip.visible: hovered + + background: Rectangle { + color: "transparent" + } + + indicator: Rectangle { + implicitWidth: 26 + implicitHeight: 26 + x: saveChatsBox.leftPadding + y: parent.height / 2 - height / 2 + border.color: theme.dialogBorder + color: "transparent" + + Rectangle { + width: 14 + height: 14 + x: 6 + y: 6 + color: theme.textColor + visible: saveChatsBox.checked + } + } + + contentItem: Text { + text: saveChatsBox.text + font: saveChatsBox.font + opacity: enabled ? 1.0 : 0.3 + color: theme.textColor + verticalAlignment: Text.AlignVCenter + leftPadding: saveChatsBox.indicator.width + saveChatsBox.spacing + } + } + Button { + Layout.row: 4 Layout.column: 1 Layout.fillWidth: true padding: 15