ChatView: make "stop" and "copy conversation" work again (#3336)

Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
AT 2024-12-20 12:26:03 -05:00 committed by GitHub
parent 93b4093761
commit 13e694e6e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 47 deletions

View File

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [3.6.1] - 2024-12-20
### Fixed
- Fix the stop generation button no longer working in v3.6.0 ([#3336](https://github.com/nomic-ai/gpt4all/pull/3336))
- Fix the copy entire conversation button no longer working in v3.6.0 ([#3336](https://github.com/nomic-ai/gpt4all/pull/3336))
## [3.6.0] - 2024-12-19 ## [3.6.0] - 2024-12-19
### Added ### Added
@ -239,6 +245,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Fix several Vulkan resource management issues ([#2694](https://github.com/nomic-ai/gpt4all/pull/2694)) - Fix several Vulkan resource management issues ([#2694](https://github.com/nomic-ai/gpt4all/pull/2694))
- Fix crash/hang when some models stop generating, by showing special tokens ([#2701](https://github.com/nomic-ai/gpt4all/pull/2701)) - Fix crash/hang when some models stop generating, by showing special tokens ([#2701](https://github.com/nomic-ai/gpt4all/pull/2701))
[3.6.1]: https://github.com/nomic-ai/gpt4all/compare/v3.6.0...v3.6.1
[3.6.0]: https://github.com/nomic-ai/gpt4all/compare/v3.5.3...v3.6.0 [3.6.0]: https://github.com/nomic-ai/gpt4all/compare/v3.5.3...v3.6.0
[3.5.3]: https://github.com/nomic-ai/gpt4all/compare/v3.5.2...v3.5.3 [3.5.3]: https://github.com/nomic-ai/gpt4all/compare/v3.5.2...v3.5.3
[3.5.2]: https://github.com/nomic-ai/gpt4all/compare/v3.5.1...v3.5.2 [3.5.2]: https://github.com/nomic-ai/gpt4all/compare/v3.5.1...v3.5.2

View File

@ -6,7 +6,7 @@ set(APP_VERSION_MAJOR 3)
set(APP_VERSION_MINOR 6) set(APP_VERSION_MINOR 6)
set(APP_VERSION_PATCH 1) set(APP_VERSION_PATCH 1)
set(APP_VERSION_BASE "${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH}") set(APP_VERSION_BASE "${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH}")
set(APP_VERSION "${APP_VERSION_BASE}-dev0") set(APP_VERSION "${APP_VERSION_BASE}")
project(gpt4all VERSION ${APP_VERSION_BASE} LANGUAGES CXX C) project(gpt4all VERSION ${APP_VERSION_BASE} LANGUAGES CXX C)

View File

@ -37,10 +37,11 @@ Rectangle {
Connections { Connections {
target: currentChat target: currentChat
function onResponseInProgressChanged() { // FIXME: https://github.com/nomic-ai/gpt4all/issues/3334
if (MySettings.networkIsActive && !currentChat.responseInProgress) // function onResponseInProgressChanged() {
Network.sendConversation(currentChat.id, getConversationJson()); // if (MySettings.networkIsActive && !currentChat.responseInProgress)
} // Network.sendConversation(currentChat.id, getConversationJson());
// }
function onModelLoadingErrorChanged() { function onModelLoadingErrorChanged() {
if (currentChat.modelLoadingError !== "") if (currentChat.modelLoadingError !== "")
modelLoadingErrorPopup.open() modelLoadingErrorPopup.open()
@ -116,42 +117,44 @@ Rectangle {
} }
} }
function getConversation() { // FIXME: https://github.com/nomic-ai/gpt4all/issues/3334
var conversation = ""; // function getConversation() {
for (var i = 0; i < chatModel.count; i++) { // var conversation = "";
var item = chatModel.get(i) // for (var i = 0; i < chatModel.count; i++) {
var string = item.name; // var item = chatModel.get(i)
var isResponse = item.name === "Response: " // var string = item.name;
string += chatModel.get(i).value // var isResponse = item.name === "Response: "
if (isResponse && item.stopped) // string += chatModel.get(i).value
string += " <stopped>" // if (isResponse && item.stopped)
string += "\n" // string += " <stopped>"
conversation += string // string += "\n"
} // conversation += string
return conversation // }
} // return conversation
// }
function getConversationJson() { // FIXME: https://github.com/nomic-ai/gpt4all/issues/3334
var str = "{\"conversation\": ["; // function getConversationJson() {
for (var i = 0; i < chatModel.count; i++) { // var str = "{\"conversation\": [";
var item = chatModel.get(i) // for (var i = 0; i < chatModel.count; i++) {
var isResponse = item.name === "Response: " // var item = chatModel.get(i)
str += "{\"content\": "; // var isResponse = item.name === "Response: "
str += JSON.stringify(item.value) // str += "{\"content\": ";
str += ", \"role\": \"" + (isResponse ? "assistant" : "user") + "\""; // str += JSON.stringify(item.value)
if (isResponse && item.thumbsUpState !== item.thumbsDownState) // str += ", \"role\": \"" + (isResponse ? "assistant" : "user") + "\"";
str += ", \"rating\": \"" + (item.thumbsUpState ? "positive" : "negative") + "\""; // if (isResponse && item.thumbsUpState !== item.thumbsDownState)
if (isResponse && item.newResponse !== "") // str += ", \"rating\": \"" + (item.thumbsUpState ? "positive" : "negative") + "\"";
str += ", \"edited_content\": " + JSON.stringify(item.newResponse); // if (isResponse && item.newResponse !== "")
if (isResponse && item.stopped) // str += ", \"edited_content\": " + JSON.stringify(item.newResponse);
str += ", \"stopped\": \"true\"" // if (isResponse && item.stopped)
if (!isResponse) // str += ", \"stopped\": \"true\""
str += "}," // if (!isResponse)
else // str += "},"
str += ((i < chatModel.count - 1) ? "}," : "}") // else
} // str += ((i < chatModel.count - 1) ? "}," : "}")
return str + "]}" // }
} // return str + "]}"
// }
ChatDrawer { ChatDrawer {
id: chatDrawer id: chatDrawer
@ -932,10 +935,7 @@ Rectangle {
visible: false visible: false
} }
onClicked: { onClicked: {
var conversation = getConversation() chatModel.copyToClipboard()
copyEdit.text = conversation
copyEdit.selectAll()
copyEdit.copy()
copyMessage.open() copyMessage.open()
} }
ToolTip.visible: copyChatButton.hovered ToolTip.visible: copyChatButton.hovered
@ -1354,9 +1354,10 @@ Rectangle {
ToolTip.text: Accessible.description ToolTip.text: Accessible.description
onClicked: { onClicked: {
var index = Math.max(0, chatModel.count - 1); // FIXME: This no longer sets a 'stopped' field so conversations that
var listElement = chatModel.get(index); // are copied to clipboard or to datalake don't indicate if the user
listElement.stopped = true // has prematurely stopped the response. This has been broken since
// v3.0.0 at least.
currentChat.stopGenerating() currentChat.stopGenerating()
} }
} }

View File

@ -982,6 +982,20 @@ public:
emit hasErrorChanged(value); emit hasErrorChanged(value);
} }
Q_INVOKABLE void copyToClipboard()
{
QMutexLocker locker(&m_mutex);
QString conversation;
for (ChatItem *item : m_chatItems) {
QString string = item->name;
string += item->clipboardContent();
string += "\n";
conversation += string;
}
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(conversation, QClipboard::Clipboard);
}
Q_INVOKABLE void copyToClipboard(int index) Q_INVOKABLE void copyToClipboard(int index)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);