Add save/restore to chatgpt chats and allow serialize/deseralize from disk.

This commit is contained in:
Adam Treat
2023-05-15 18:36:41 -04:00
committed by AT
parent 0cd509d530
commit f931de21c5
7 changed files with 120 additions and 12 deletions

View File

@@ -38,6 +38,19 @@ void ChatListModel::setShouldSaveChats(bool b)
emit shouldSaveChatsChanged();
}
bool ChatListModel::shouldSaveChatGPTChats() const
{
return m_shouldSaveChatGPTChats;
}
void ChatListModel::setShouldSaveChatGPTChats(bool b)
{
if (m_shouldSaveChatGPTChats == b)
return;
m_shouldSaveChatGPTChats = b;
emit shouldSaveChatGPTChatsChanged();
}
void ChatListModel::removeChatFile(Chat *chat) const
{
Q_ASSERT(chat != m_serverChat);
@@ -52,15 +65,17 @@ void ChatListModel::removeChatFile(Chat *chat) const
void ChatListModel::saveChats() const
{
if (!m_shouldSaveChats)
return;
QElapsedTimer timer;
timer.start();
const QString savePath = Download::globalInstance()->downloadLocalModelsPath();
for (Chat *chat : m_chats) {
if (chat == m_serverChat)
continue;
const bool isChatGPT = chat->modelName().startsWith("chatgpt-");
if (!isChatGPT && !m_shouldSaveChats)
continue;
if (isChatGPT && !m_shouldSaveChatGPTChats)
continue;
QString fileName = "gpt4all-" + chat->id() + ".chat";
QFile file(savePath + "/" + fileName);
bool success = file.open(QIODevice::WriteOnly);