diff --git a/chat.h b/chat.h index 238a8695..1934b3df 100644 --- a/chat.h +++ b/chat.h @@ -28,6 +28,12 @@ public: QString name() const { return m_name; } ChatModel *chatModel() { return m_chatModel; } + Q_INVOKABLE void reset() + { + m_id = Network::globalInstance()->generateUniqueId(); + m_chatModel->clear(); + } + Q_SIGNALS: void idChanged(); void nameChanged(); diff --git a/chatmodel.h b/chatmodel.h index 1102b008..c393d347 100644 --- a/chatmodel.h +++ b/chatmodel.h @@ -125,6 +125,16 @@ public: emit countChanged(); } + Q_INVOKABLE void clear() + { + if (m_chatItems.isEmpty()) return; + + beginResetModel(); + m_chatItems.clear(); + endResetModel(); + emit countChanged(); + } + Q_INVOKABLE ChatItem get(int index) { if (index < 0 || index >= m_chatItems.size()) return ChatItem(); diff --git a/main.qml b/main.qml index a0174310..bd2288b5 100644 --- a/main.qml +++ b/main.qml @@ -18,7 +18,6 @@ Window { id: theme } - property string chatId: Network.generateUniqueId() property var chatModel: LLM.currentChat.chatModel color: theme.textColor @@ -172,7 +171,7 @@ Window { onActivated: { LLM.stopGenerating() LLM.modelName = comboBox.currentText - chatModel.clear() + LLM.currentChat.reset(); } } } @@ -474,8 +473,7 @@ Window { onClicked: { LLM.stopGenerating() LLM.resetContext() - chatId = Network.generateUniqueId() - chatModel.clear() + LLM.currentChat.reset(); } } @@ -750,7 +748,7 @@ Window { chatModel.updateNewResponse(index, response) chatModel.updateThumbsUpState(index, false) chatModel.updateThumbsDownState(index, true) - Network.sendConversation(chatId, getConversationJson()); + Network.sendConversation(LLM.currentChat.id, getConversationJson()); } } @@ -782,7 +780,7 @@ Window { chatModel.updateNewResponse(index, "") chatModel.updateThumbsUpState(index, true) chatModel.updateThumbsDownState(index, false) - Network.sendConversation(chatId, getConversationJson()); + Network.sendConversation(LLM.currentChat.id, getConversationJson()); } }