Turn off saving chats to disk by default as it eats so much disk space.

pull/520/head
Adam Treat 1 year ago
parent 6d4d86d07c
commit 8d2c8c8cb0

@ -3,6 +3,19 @@
#include <QFile>
#include <QDataStream>
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();

@ -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<Chat*> m_chats;

@ -306,6 +306,16 @@ void Network::sendNetworkToggled(bool isActive)
sendMixpanelEvent("network_toggled", QVector<KeyValue>{kv});
}
void Network::sendSaveChatsToggled(bool isActive)
{
if (!m_usageStatsActive)
return;
KeyValue kv;
kv.key = QString("isActive");
kv.value = QJsonValue(isActive);
sendMixpanelEvent("savechats_toggled", QVector<KeyValue>{kv});
}
void Network::sendNewChat(int count)
{
if (!m_usageStatsActive)

@ -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();

@ -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

Loading…
Cancel
Save