From 45c53ee6ac8d8129939f02d234127e25f580474f Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Fri, 20 Dec 2024 06:51:36 -0500 Subject: [PATCH] The ChatModel::get method was removed which unfortunately caused a regression in a few places in QML that were using this method. This PR fixes two of these issues: * Issue #3333 - the stop generation button no longer working * Issue #3335 - the copy entire conversation button no longer working It also adds a fixme in the code for a third issue which is less of a priority: * Issue #3334 - not sending the conversation to the datalake. Signed-off-by: Adam Treat --- gpt4all-chat/qml/ChatView.qml | 88 +++++++++++++++++------------------ gpt4all-chat/src/chatmodel.h | 11 +++++ 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/gpt4all-chat/qml/ChatView.qml b/gpt4all-chat/qml/ChatView.qml index 431d63986f23..b3490d5d5fd6 100644 --- a/gpt4all-chat/qml/ChatView.qml +++ b/gpt4all-chat/qml/ChatView.qml @@ -37,10 +37,11 @@ Rectangle { Connections { target: currentChat - function onResponseInProgressChanged() { - if (MySettings.networkIsActive && !currentChat.responseInProgress) - Network.sendConversation(currentChat.id, getConversationJson()); - } + // FIXME: https://github.com/nomic-ai/gpt4all/issues/3334 + // function onResponseInProgressChanged() { + // if (MySettings.networkIsActive && !currentChat.responseInProgress) + // Network.sendConversation(currentChat.id, getConversationJson()); + // } function onModelLoadingErrorChanged() { if (currentChat.modelLoadingError !== "") modelLoadingErrorPopup.open() @@ -116,42 +117,44 @@ Rectangle { } } - function getConversation() { - var conversation = ""; - for (var i = 0; i < chatModel.count; i++) { - var item = chatModel.get(i) - var string = item.name; - var isResponse = item.name === "Response: " - string += chatModel.get(i).value - if (isResponse && item.stopped) - string += " " - string += "\n" - conversation += string - } - return conversation - } - - function getConversationJson() { - var str = "{\"conversation\": ["; - for (var i = 0; i < chatModel.count; i++) { - var item = chatModel.get(i) - var isResponse = item.name === "Response: " - str += "{\"content\": "; - str += JSON.stringify(item.value) - str += ", \"role\": \"" + (isResponse ? "assistant" : "user") + "\""; - if (isResponse && item.thumbsUpState !== item.thumbsDownState) - str += ", \"rating\": \"" + (item.thumbsUpState ? "positive" : "negative") + "\""; - if (isResponse && item.newResponse !== "") - str += ", \"edited_content\": " + JSON.stringify(item.newResponse); - if (isResponse && item.stopped) - str += ", \"stopped\": \"true\"" - if (!isResponse) - str += "}," - else - str += ((i < chatModel.count - 1) ? "}," : "}") - } - return str + "]}" - } + // FIXME: https://github.com/nomic-ai/gpt4all/issues/3334 + // function getConversation() { + // var conversation = ""; + // for (var i = 0; i < chatModel.count; i++) { + // var item = chatModel.get(i) + // var string = item.name; + // var isResponse = item.name === "Response: " + // string += chatModel.get(i).value + // if (isResponse && item.stopped) + // string += " " + // string += "\n" + // conversation += string + // } + // return conversation + // } + + // FIXME: https://github.com/nomic-ai/gpt4all/issues/3334 + // function getConversationJson() { + // var str = "{\"conversation\": ["; + // for (var i = 0; i < chatModel.count; i++) { + // var item = chatModel.get(i) + // var isResponse = item.name === "Response: " + // str += "{\"content\": "; + // str += JSON.stringify(item.value) + // str += ", \"role\": \"" + (isResponse ? "assistant" : "user") + "\""; + // if (isResponse && item.thumbsUpState !== item.thumbsDownState) + // str += ", \"rating\": \"" + (item.thumbsUpState ? "positive" : "negative") + "\""; + // if (isResponse && item.newResponse !== "") + // str += ", \"edited_content\": " + JSON.stringify(item.newResponse); + // if (isResponse && item.stopped) + // str += ", \"stopped\": \"true\"" + // if (!isResponse) + // str += "}," + // else + // str += ((i < chatModel.count - 1) ? "}," : "}") + // } + // return str + "]}" + // } ChatDrawer { id: chatDrawer @@ -932,7 +935,7 @@ Rectangle { visible: false } onClicked: { - var conversation = getConversation() + var conversation = chatModel.copyToClipboard() copyEdit.text = conversation copyEdit.selectAll() copyEdit.copy() @@ -1354,9 +1357,6 @@ Rectangle { ToolTip.text: Accessible.description onClicked: { - var index = Math.max(0, chatModel.count - 1); - var listElement = chatModel.get(index); - listElement.stopped = true currentChat.stopGenerating() } } diff --git a/gpt4all-chat/src/chatmodel.h b/gpt4all-chat/src/chatmodel.h index 82dbc68fdc7f..d0a8cbfd9759 100644 --- a/gpt4all-chat/src/chatmodel.h +++ b/gpt4all-chat/src/chatmodel.h @@ -982,6 +982,17 @@ class ChatModel : public QAbstractListModel emit hasErrorChanged(value); } + Q_INVOKABLE void copyToClipboard() + { + QMutexLocker locker(&m_mutex); + QStringList content; + for (ChatItem *item : m_chatItems) { + content << item->clipboardContent(); + } + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setText(content.join("\n\n"), QClipboard::Clipboard); + } + Q_INVOKABLE void copyToClipboard(int index) { QMutexLocker locker(&m_mutex);