gpt4all/gpt4all-chat/main.qml

1067 lines
40 KiB
QML
Raw Normal View History

import QtCore
2023-04-08 23:28:39 -04:00
import QtQuick
import QtQuick.Controls
2023-04-10 15:03:00 -04:00
import QtQuick.Controls.Basic
2023-04-16 01:14:42 -04:00
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
2023-04-08 23:28:39 -04:00
import llm
2023-06-22 15:44:49 -04:00
import chatlistmodel
2023-04-28 10:54:05 -04:00
import download
2023-06-22 15:44:49 -04:00
import modellist
import network
import gpt4all
import mysettings
2023-04-08 23:28:39 -04:00
Window {
id: window
width: 1280
height: 720
minimumWidth: 720
minimumHeight: 480
2023-04-08 23:28:39 -04:00
visible: true
title: qsTr("GPT4All v") + Qt.application.version
Theme {
id: theme
}
2023-06-22 15:44:49 -04:00
property var currentChat: ChatListModel.currentChat
2023-05-01 17:13:20 -04:00
property var chatModel: currentChat.chatModel
property bool hasSaved: false
onClosing: function(close) {
if (window.hasSaved)
return;
savingPopup.open();
2023-06-22 15:44:49 -04:00
ChatListModel.saveChats();
close.accepted = false
}
Connections {
2023-06-22 15:44:49 -04:00
target: ChatListModel
function onSaveChatsFinished() {
window.hasSaved = true;
savingPopup.close();
window.close()
}
}
2023-04-23 21:05:38 -04:00
color: theme.backgroundDarkest
2023-04-28 10:54:05 -04:00
// Startup code
Component.onCompleted: {
startupDialogs();
2023-04-28 10:54:05 -04:00
}
Connections {
target: firstStartDialog
function onClosed() {
startupDialogs();
}
}
Connections {
target: downloadNewModels
function onClosed() {
startupDialogs();
}
}
Connections {
target: Download
function onHasNewerReleaseChanged() {
startupDialogs();
}
}
Connections {
target: currentChat
function onResponseInProgressChanged() {
if (MySettings.networkIsActive && !currentChat.responseInProgress)
Network.sendConversation(currentChat.id, getConversationJson());
}
function onModelLoadingErrorChanged() {
if (currentChat.modelLoadingError !== "")
modelLoadingErrorPopup.open()
}
}
property bool hasShownModelDownload: false
2023-04-28 10:54:05 -04:00
function startupDialogs() {
if (!LLM.compatHardware) {
Network.sendNonCompatHardware();
errorCompatHardware.open();
return;
}
2023-04-28 10:54:05 -04:00
// check for first time start of this version
if (Download.isFirstStart()) {
firstStartDialog.open();
return;
}
// check for any current models and if not, open download dialog once
if (!hasShownModelDownload && ModelList.installedModels.count === 0 && !firstStartDialog.opened) {
2023-04-28 10:54:05 -04:00
downloadNewModels.open();
hasShownModelDownload = true;
2023-04-28 10:54:05 -04:00
return;
}
// check for new version
if (Download.hasNewerRelease && !firstStartDialog.opened && !downloadNewModels.opened) {
2023-04-28 10:54:05 -04:00
newVersionDialog.open();
return;
}
}
PopupDialog {
id: errorCompatHardware
anchors.centerIn: parent
shouldTimeOut: false
shouldShowBusy: false
closePolicy: Popup.NoAutoClose
modal: true
text: qsTr("<h3>Encountered an error starting up:</h3><br>")
+ qsTr("<i>\"Incompatible hardware detected.\"</i>")
+ qsTr("<br><br>Unfortunately, your CPU does not meet the minimal requirements to run ")
+ qsTr("this program. In particular, it does not support AVX intrinsics which this ")
+ qsTr("program requires to successfully run a modern large language model. ")
+ qsTr("The only solution at this time is to upgrade your hardware to a more modern CPU.")
2023-06-26 13:37:18 -04:00
+ qsTr("<br><br>See here for more information: <a href=\"https://en.wikipedia.org/wiki/Advanced_Vector_Extensions\">")
+ qsTr("https://en.wikipedia.org/wiki/Advanced_Vector_Extensions</a>")
}
2023-04-28 10:54:05 -04:00
StartupDialog {
id: firstStartDialog
anchors.centerIn: parent
}
NewVersionDialog {
id: newVersionDialog
anchors.centerIn: parent
}
2023-05-05 10:47:05 -04:00
AboutDialog {
id: aboutDialog
anchors.centerIn: parent
2023-06-02 20:05:47 -04:00
width: Math.min(1024, window.width - (window.width * .2))
height: Math.min(600, window.height - (window.height * .2))
2023-05-05 10:47:05 -04:00
}
2023-04-18 08:39:48 -04:00
Item {
Accessible.role: Accessible.Window
Accessible.name: title
}
PopupDialog {
id: modelLoadingErrorPopup
anchors.centerIn: parent
shouldTimeOut: false
2023-06-22 15:44:49 -04:00
text: qsTr("<h3>Encountered an error loading model:</h3><br>")
+ "<i>\"" + currentChat.modelLoadingError + "\"</i>"
+ qsTr("<br><br>Model loading failures can happen for a variety of reasons, but the most common "
+ "causes include a bad file format, an incomplete or corrupted download, the wrong file "
+ "type or an incompatible model type. Here are some suggestions for resolving the problem:"
+ "<br><ul>"
+ "<li>Ensure the model file has a compatible ggml format and type"
+ "<li>Check the model file is complete in the download folder"
+ "<li>You can find the download folder in the settings dialog"
+ "<li>If you've sideloaded the model ensure the file is not corrupt by checking md5sum"
2023-06-26 13:37:18 -04:00
+ "<li>Read more about what models are supported in our <a href=\"https://docs.gpt4all.io/gpt4all_chat.html\">documentation</a> for the gui"
2023-06-22 15:44:49 -04:00
+ "<li>Check out our <a href=\"https://discord.gg/4M2QFmTt2k\">discord channel</a> for help")
}
Rectangle {
2023-04-10 23:34:34 -04:00
id: header
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
height: 100
color: theme.backgroundDarkest
Item {
anchors.centerIn: parent
height: childrenRect.height
visible: currentChat.isModelLoaded || currentChat.modelLoadingError !== "" || currentChat.isServer
Label {
id: modelLabel
color: theme.textColor
padding: 20
2023-05-01 17:13:20 -04:00
font.pixelSize: theme.fontSizeLarger
text: ""
background: Rectangle {
color: theme.backgroundDarkest
}
horizontalAlignment: TextInput.AlignRight
}
2023-05-22 09:01:46 -04:00
MyComboBox {
id: comboBox
implicitWidth: 375
width: window.width >= 750 ? implicitWidth : implicitWidth - ((750 - window.width))
anchors.top: modelLabel.top
anchors.bottom: modelLabel.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.horizontalCenterOffset: window.width >= 950 ? 0 : Math.max(-((950 - window.width) / 2), -99.5)
2023-05-11 16:46:25 -04:00
enabled: !currentChat.isServer
2023-06-22 15:44:49 -04:00
model: ModelList.installedModels
valueRole: "id"
2023-06-22 15:44:49 -04:00
textRole: "name"
property string currentModelName: ""
function updateCurrentModelName() {
var info = ModelList.modelInfo(currentChat.modelInfo.id);
comboBox.currentModelName = info.name;
}
2023-06-22 15:44:49 -04:00
Connections {
target: currentChat
function onModelInfoChanged() {
comboBox.updateCurrentModelName();
2023-06-22 15:44:49 -04:00
}
}
Connections {
target: window
function onCurrentChatChanged() {
comboBox.updateCurrentModelName();
}
}
background: Rectangle {
color: theme.backgroundDark
radius: 10
}
contentItem: Text {
anchors.horizontalCenter: parent.horizontalCenter
leftPadding: 10
rightPadding: 20
text: currentChat.modelLoadingError !== ""
? qsTr("Model loading error...")
: comboBox.currentModelName
font: comboBox.font
color: theme.textColor
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
}
delegate: ItemDelegate {
width: comboBox.width
contentItem: Text {
text: name
color: theme.textColor
font: comboBox.font
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: highlighted ? theme.backgroundLight : theme.backgroundDark
}
highlighted: comboBox.highlightedIndex === index
}
Accessible.role: Accessible.ComboBox
Accessible.name: qsTr("ComboBox for displaying/picking the current model")
Accessible.description: qsTr("Use this for picking the current model to use; the first item is the current model")
onActivated: function (index) {
2023-05-01 17:13:20 -04:00
currentChat.stopGenerating()
currentChat.reset();
currentChat.modelInfo = ModelList.modelInfo(comboBox.valueAt(index))
}
}
2023-04-10 23:34:34 -04:00
}
2023-04-08 23:28:39 -04:00
Item {
anchors.centerIn: parent
visible: ModelList.installedModels.count
&& !currentChat.isModelLoaded
&& currentChat.modelLoadingError === ""
&& !currentChat.isServer
width: childrenRect.width
height: childrenRect.height
Row {
spacing: 5
MyBusyIndicator {
anchors.verticalCenter: parent.verticalCenter
running: parent.visible
Accessible.role: Accessible.Animation
Accessible.name: qsTr("Busy indicator")
Accessible.description: qsTr("Displayed when the model is loading")
}
Label {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("Loading model...")
color: theme.textAccent
}
}
}
2023-04-10 23:34:34 -04:00
}
2023-04-23 06:58:07 -04:00
SettingsDialog {
2023-04-16 01:14:42 -04:00
id: settingsDialog
anchors.centerIn: parent
width: Math.min(1280, window.width - (window.width * .1))
height: window.height - (window.height * .1)
2023-04-16 01:14:42 -04:00
}
2023-04-10 23:34:34 -04:00
Button {
id: drawerButton
anchors.left: parent.left
2023-04-10 23:34:34 -04:00
anchors.top: parent.top
anchors.topMargin: 30
anchors.leftMargin: 30
width: 40
2023-04-10 23:34:34 -04:00
height: 40
z: 200
padding: 15
2023-04-18 08:39:48 -04:00
Accessible.role: Accessible.ButtonMenu
Accessible.name: qsTr("Hamburger button")
Accessible.description: qsTr("Hamburger button that reveals a drawer on the left of the application")
2023-04-10 23:34:34 -04:00
background: Item {
anchors.centerIn: parent
width: 30
height: 30
2023-04-10 23:34:34 -04:00
Rectangle {
id: bar1
color: drawerButton.hovered ? theme.textColor : theme.backgroundLightest
2023-04-10 23:34:34 -04:00
width: parent.width
height: 6
2023-04-10 23:34:34 -04:00
radius: 2
antialiasing: true
}
Rectangle {
id: bar2
anchors.centerIn: parent
color: drawerButton.hovered ? theme.textColor : theme.backgroundLightest
2023-04-10 23:34:34 -04:00
width: parent.width
height: 6
2023-04-10 23:34:34 -04:00
radius: 2
antialiasing: true
}
Rectangle {
id: bar3
anchors.bottom: parent.bottom
color: drawerButton.hovered ? theme.textColor : theme.backgroundLightest
2023-04-10 23:34:34 -04:00
width: parent.width
height: 6
2023-04-10 23:34:34 -04:00
radius: 2
antialiasing: true
}
}
onClicked: {
drawer.visible = !drawer.visible
}
}
NetworkDialog {
id: networkDialog
anchors.centerIn: parent
width: Math.min(1024, window.width - (window.width * .2))
height: Math.min(600, window.height - (window.height * .2))
Item {
Accessible.role: Accessible.Dialog
Accessible.name: qsTr("Network dialog")
Accessible.description: qsTr("Dialog for opt-in to sharing feedback/conversations")
}
}
MyToolButton {
id: networkButton
2023-04-08 23:28:39 -04:00
anchors.right: parent.right
anchors.top: parent.top
2023-04-24 00:31:39 -04:00
anchors.topMargin: 30
anchors.rightMargin: 30
2023-04-24 00:25:57 -04:00
width: 40
2023-04-24 00:31:39 -04:00
height: 40
z: 200
padding: 15
toggled: MySettings.networkIsActive
source: "qrc:/gpt4all/icons/network.svg"
Accessible.name: qsTr("Network button")
Accessible.description: qsTr("Reveals a dialogue where you can opt-in for sharing data over network")
onClicked: {
if (MySettings.networkIsActive) {
MySettings.networkIsActive = false
Network.sendNetworkToggled(false);
} else
networkDialog.open()
}
}
Connections {
target: Network
function onHealthCheckFailed(code) {
healthCheckFailed.open();
}
}
CollectionsDialog {
id: collectionsDialog
anchors.centerIn: parent
}
MyToolButton {
id: collectionsButton
anchors.right: networkButton.left
anchors.top: parent.top
2023-04-10 23:34:34 -04:00
anchors.topMargin: 30
anchors.rightMargin: 10
2023-04-24 00:25:57 -04:00
width: 40
2023-04-10 23:34:34 -04:00
height: 40
z: 200
padding: 15
toggled: currentChat.collectionList.length
source: "qrc:/gpt4all/icons/db.svg"
Accessible.name: qsTr("Add collections of documents to the chat")
Accessible.description: qsTr("Provides a button to add collections of documents to the chat")
onClicked: {
collectionsDialog.open()
}
}
MyToolButton {
id: settingsButton
anchors.right: collectionsButton.left
anchors.top: parent.top
anchors.topMargin: 30
anchors.rightMargin: 10
width: 40
height: 40
z: 200
padding: 15
source: "qrc:/gpt4all/icons/settings.svg"
2023-04-18 08:39:48 -04:00
Accessible.name: qsTr("Settings button")
Accessible.description: qsTr("Reveals a dialogue where you can change various settings")
onClicked: {
settingsDialog.open()
}
}
PopupDialog {
id: copyMessage
anchors.centerIn: parent
text: qsTr("Conversation copied to clipboard.")
}
PopupDialog {
id: copyCodeMessage
anchors.centerIn: parent
text: qsTr("Code copied to clipboard.")
}
PopupDialog {
id: healthCheckFailed
anchors.centerIn: parent
text: qsTr("Connection to datalake failed.")
}
PopupDialog {
id: recalcPopup
anchors.centerIn: parent
shouldTimeOut: false
shouldShowBusy: true
text: qsTr("Recalculating context.")
Connections {
target: currentChat
function onRecalcChanged() {
if (currentChat.isRecalc)
recalcPopup.open()
else
recalcPopup.close()
}
}
}
PopupDialog {
id: savingPopup
anchors.centerIn: parent
shouldTimeOut: false
shouldShowBusy: true
text: qsTr("Saving chats.")
}
MyToolButton {
id: copyButton
anchors.right: settingsButton.left
anchors.top: parent.top
anchors.topMargin: 30
anchors.rightMargin: 10
2023-04-24 00:25:57 -04:00
width: 40
height: 40
z: 200
padding: 15
source: "qrc:/gpt4all/icons/copy.svg"
2023-04-18 08:39:48 -04:00
Accessible.name: qsTr("Copy button")
Accessible.description: qsTr("Copy the conversation to the clipboard")
2023-04-11 08:54:57 -04:00
TextEdit{
id: copyEdit
visible: false
}
onClicked: {
var conversation = getConversation()
2023-04-11 08:54:57 -04:00
copyEdit.text = conversation
copyEdit.selectAll()
copyEdit.copy()
copyMessage.open()
2023-04-11 08:54:57 -04:00
}
}
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 === qsTr("Response: ")
string += chatModel.get(i).value
if (isResponse && item.stopped)
string += " <stopped>"
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 === qsTr("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 !== "")
2023-04-25 22:49:23 -04:00
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 + "]}"
}
MyToolButton {
2023-04-11 08:54:57 -04:00
id: resetContextButton
anchors.right: copyButton.left
anchors.top: parent.top
anchors.topMargin: 30
anchors.rightMargin: 10
2023-04-24 00:25:57 -04:00
width: 40
2023-04-11 08:54:57 -04:00
height: 40
z: 200
padding: 15
source: "qrc:/gpt4all/icons/regenerate.svg"
2023-04-11 08:54:57 -04:00
2023-04-18 08:39:48 -04:00
Accessible.name: text
Accessible.description: qsTr("Reset the context which erases current conversation")
2023-04-10 23:34:34 -04:00
onClicked: {
Network.sendResetContext(chatModel.count)
2023-05-01 17:13:20 -04:00
currentChat.reset();
currentChat.processSystemPrompt();
2023-04-10 23:34:34 -04:00
}
}
Dialog {
id: checkForUpdatesError
anchors.centerIn: parent
modal: false
opacity: 0.9
padding: 20
2023-04-10 23:34:34 -04:00
Text {
horizontalAlignment: Text.AlignJustify
text: qsTr("ERROR: Update system could not find the MaintenanceTool used<br>
to check for updates!<br><br>
Did you install this application using the online installer? If so,<br>
the MaintenanceTool executable should be located one directory<br>
above where this application resides on your filesystem.<br><br>
If you can't start it manually, then I'm afraid you'll have to<br>
reinstall.")
color: theme.textColor
2023-04-18 08:39:48 -04:00
Accessible.role: Accessible.Dialog
Accessible.name: text
Accessible.description: qsTr("Dialog indicating an error")
2023-04-10 23:34:34 -04:00
}
background: Rectangle {
anchors.fill: parent
color: theme.backgroundDarkest
2023-04-10 23:34:34 -04:00
border.width: 1
border.color: theme.dialogBorder
2023-04-10 23:34:34 -04:00
radius: 10
}
}
2023-04-18 21:10:06 -04:00
ModelDownloaderDialog {
id: downloadNewModels
anchors.centerIn: parent
width: Math.min(1280, window.width - (window.width * .1))
height: window.height - (window.height * .1)
2023-04-18 21:10:06 -04:00
Item {
Accessible.role: Accessible.Dialog
Accessible.name: qsTr("Download new models dialog")
Accessible.description: qsTr("Dialog for downloading new models")
}
}
ChatDrawer {
2023-04-10 23:34:34 -04:00
id: drawer
y: header.height
width: Math.min(600, 0.3 * window.width)
2023-04-10 23:34:34 -04:00
height: window.height - y
onDownloadClicked: {
downloadNewModels.open()
}
2023-05-05 10:47:05 -04:00
onAboutClicked: {
aboutDialog.open()
}
2023-04-10 23:34:34 -04:00
}
2023-05-25 10:40:10 -04:00
PopupDialog {
id: referenceContextDialog
anchors.centerIn: parent
shouldTimeOut: false
shouldShowBusy: false
modal: true
}
2023-04-10 23:34:34 -04:00
Rectangle {
id: conversation
color: theme.backgroundLight
2023-04-10 23:34:34 -04:00
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.top: header.bottom
2023-04-08 23:28:39 -04:00
ScrollView {
id: scrollView
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
2023-05-11 16:46:25 -04:00
anchors.bottom: !currentChat.isServer ? textInputView.top : parent.bottom
anchors.bottomMargin: !currentChat.isServer ? 30 : 0
2023-04-08 23:28:39 -04:00
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
Rectangle {
anchors.fill: parent
color: currentChat.isServer ? theme.backgroundDark : theme.backgroundLight
Text {
2023-07-09 15:51:59 -04:00
id: warningLabel
text: qsTr("You must install a model to continue. Models are available via the download dialog or you can install them manually by downloading from <a href=\"https://gpt4all.io\">the GPT4All website</a> (look for the Models Explorer) and placing them in the model folder. The model folder can be found in the settings dialog under the application tab.")
color: theme.textColor
2023-07-09 15:51:59 -04:00
width: 600
linkColor: theme.linkColor
wrapMode: Text.WordWrap
anchors.centerIn: parent
visible: ModelList.installedModels.count === 0
2023-07-09 15:51:59 -04:00
onLinkActivated: function(link) {
Qt.openUrlExternally(link)
}
}
MyButton {
id: downloadButton
text: qsTr("Download models")
visible: ModelList.installedModels.count === 0
anchors.top: warningLabel.bottom
anchors.topMargin: 20
anchors.horizontalCenter: warningLabel.horizontalCenter
padding: 15
leftPadding: 50
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 15
width: 24
height: 24
mipmap: true
source: "qrc:/gpt4all/icons/download.svg"
}
background: Rectangle {
border.color: downloadButton.down ? theme.backgroundLightest : theme.buttonBorder
border.width: 2
radius: 10
color: downloadButton.hovered ? theme.backgroundLighter : theme.backgroundLight
}
onClicked: {
downloadNewModels.open();
}
}
2023-04-08 23:28:39 -04:00
ListView {
id: listView
visible: ModelList.installedModels.count !== 0
2023-04-08 23:28:39 -04:00
anchors.fill: parent
model: chatModel
2023-04-18 08:39:48 -04:00
Accessible.role: Accessible.List
Accessible.name: qsTr("List of prompt/response pairs")
Accessible.description: qsTr("This is the list of prompt/response pairs comprising the actual conversation with the model")
2023-04-08 23:28:39 -04:00
delegate: TextArea {
id: myTextArea
text: value + references
width: listView.width
color: theme.textColor
2023-04-08 23:28:39 -04:00
wrapMode: Text.WordWrap
textFormat: TextEdit.PlainText
2023-04-08 23:28:39 -04:00
focus: false
readOnly: true
2023-04-23 11:23:02 -04:00
font.pixelSize: theme.fontSizeLarge
cursorVisible: currentResponse ? currentChat.responseInProgress : false
2023-04-08 23:28:39 -04:00
cursorPosition: text.length
background: Rectangle {
opacity: 1.0
2023-05-11 16:46:25 -04:00
color: name === qsTr("Response: ")
? (currentChat.isServer ? theme.backgroundDarkest : theme.backgroundLighter)
: (currentChat.isServer ? theme.backgroundDark : theme.backgroundLight)
2023-04-08 23:28:39 -04:00
}
2023-06-11 13:24:56 -04:00
TapHandler {
id: tapHandler
onTapped: function(eventPoint, button) {
var clickedPos = myTextArea.positionAt(eventPoint.position.x, eventPoint.position.y);
var link = responseText.getLinkAtPosition(clickedPos);
2023-06-11 13:24:56 -04:00
if (link.startsWith("context://")) {
var integer = parseInt(link.split("://")[1]);
referenceContextDialog.text = referencesContext[integer - 1];
referenceContextDialog.open();
} else {
var success = responseText.tryCopyAtPosition(clickedPos);
if (success)
copyCodeMessage.open();
2023-06-11 13:24:56 -04:00
}
}
}
ResponseText {
id: responseText
}
Component.onCompleted: {
responseText.setLinkColor(theme.linkColor);
responseText.setHeaderColor(name === qsTr("Response: ") ? theme.backgroundLight : theme.backgroundLighter);
responseText.textDocument = textDocument
}
2023-04-18 08:39:48 -04:00
Accessible.role: Accessible.Paragraph
Accessible.name: name
Accessible.description: name === qsTr("Response: ") ? "The response by the model" : "The prompt by the user"
topPadding: 20
bottomPadding: 20
leftPadding: 70
rightPadding: 100
2023-04-08 23:28:39 -04:00
Item {
anchors.left: parent.left
anchors.leftMargin: 60
y: parent.topPadding + (parent.positionToRectangle(0).height / 2) - (height / 2)
visible: (currentResponse ? true : false) && value === "" && currentChat.responseInProgress
width: childrenRect.width
height: childrenRect.height
Row {
spacing: 5
MyBusyIndicator {
anchors.verticalCenter: parent.verticalCenter
running: (currentResponse ? true : false) && value === "" && currentChat.responseInProgress
Accessible.role: Accessible.Animation
Accessible.name: qsTr("Busy indicator")
Accessible.description: qsTr("Displayed when the model is thinking")
}
Label {
anchors.verticalCenter: parent.verticalCenter
text: currentChat.responseState + "..."
color: theme.textAccent
}
}
}
2023-04-08 23:28:39 -04:00
Rectangle {
anchors.left: parent.left
anchors.leftMargin: 20
y: parent.topPadding + (parent.positionToRectangle(0).height / 2) - (height / 2)
2023-04-08 23:28:39 -04:00
width: 30
height: 30
radius: 5
color: name === qsTr("Response: ") ? theme.assistantColor : theme.userColor
2023-04-08 23:28:39 -04:00
Text {
anchors.centerIn: parent
text: name === qsTr("Response: ") ? "R" : "P"
color: "white"
}
}
ThumbsDownDialog {
id: thumbsDownDialog
property point globalPoint: mapFromItem(window,
window.width / 2 - width / 2,
window.height / 2 - height / 2)
x: globalPoint.x
y: globalPoint.y
property string text: value
2023-04-27 11:44:41 -04:00
response: newResponse === undefined || newResponse === "" ? text : newResponse
onAccepted: {
var responseHasChanged = response !== text && response !== newResponse
if (thumbsDownState && !thumbsUpState && !responseHasChanged)
return
chatModel.updateNewResponse(index, response)
chatModel.updateThumbsUpState(index, false)
chatModel.updateThumbsDownState(index, true)
2023-05-01 17:13:20 -04:00
Network.sendConversation(currentChat.id, getConversationJson());
}
}
Column {
visible: name === qsTr("Response: ") &&
(!currentResponse || !currentChat.responseInProgress) && MySettings.networkIsActive
anchors.right: parent.right
anchors.rightMargin: 20
y: parent.topPadding + (parent.positionToRectangle(0).height / 2) - (height / 2)
spacing: 10
Item {
width: childrenRect.width
height: childrenRect.height
MyToolButton {
id: thumbsUp
width: 30
height: 30
opacity: thumbsUpState || thumbsUpState == thumbsDownState ? 1.0 : 0.2
source: "qrc:/gpt4all/icons/thumbs_up.svg"
2023-05-23 18:19:36 -04:00
Accessible.name: qsTr("Thumbs up")
Accessible.description: qsTr("Gives a thumbs up to the response")
onClicked: {
if (thumbsUpState && !thumbsDownState)
return
chatModel.updateNewResponse(index, "")
chatModel.updateThumbsUpState(index, true)
chatModel.updateThumbsDownState(index, false)
2023-05-01 17:13:20 -04:00
Network.sendConversation(currentChat.id, getConversationJson());
}
}
MyToolButton {
id: thumbsDown
anchors.top: thumbsUp.top
anchors.topMargin: 10
anchors.left: thumbsUp.right
anchors.leftMargin: 2
width: 30
height: 30
checked: thumbsDownState
opacity: thumbsDownState || thumbsUpState == thumbsDownState ? 1.0 : 0.2
transform: [
Matrix4x4 {
matrix: Qt.matrix4x4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
},
Translate {
x: thumbsDown.width
}
]
source: "qrc:/gpt4all/icons/thumbs_down.svg"
2023-05-23 18:19:36 -04:00
Accessible.name: qsTr("Thumbs down")
Accessible.description: qsTr("Opens thumbs down dialog")
onClicked: {
thumbsDownDialog.open()
}
}
}
}
2023-04-08 23:28:39 -04:00
}
property bool shouldAutoScroll: true
property bool isAutoScrolling: false
Connections {
target: currentChat
2023-04-08 23:28:39 -04:00
function onResponseChanged() {
if (listView.shouldAutoScroll) {
listView.isAutoScrolling = true
listView.positionViewAtEnd()
listView.isAutoScrolling = false
}
}
}
onContentYChanged: {
if (!isAutoScrolling)
shouldAutoScroll = atYEnd
}
Component.onCompleted: {
shouldAutoScroll = true
positionViewAtEnd()
}
footer: Item {
id: bottomPadding
width: parent.width
height: 60
}
}
Image {
2023-06-22 15:44:49 -04:00
visible: currentChat.isServer || currentChat.modelInfo.isChatGPT
anchors.fill: parent
sourceSize.width: 1024
sourceSize.height: 1024
fillMode: Image.PreserveAspectFit
opacity: 0.15
source: "qrc:/gpt4all/icons/network.svg"
}
2023-04-08 23:28:39 -04:00
}
}
MyButton {
id: myButton
2023-05-11 16:46:25 -04:00
visible: chatModel.count && !currentChat.isServer
2023-04-08 23:28:39 -04:00
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 15
2023-05-01 17:13:20 -04:00
source: currentChat.responseInProgress ? "qrc:/gpt4all/icons/stop_generating.svg" : "qrc:/gpt4all/icons/regenerate.svg"
2023-04-08 23:28:39 -04:00
}
2023-04-09 07:38:25 -04:00
leftPadding: 50
2023-04-08 23:28:39 -04:00
onClicked: {
var index = Math.max(0, chatModel.count - 1);
var listElement = chatModel.get(index);
2023-05-01 17:13:20 -04:00
if (currentChat.responseInProgress) {
listElement.stopped = true
2023-05-01 17:13:20 -04:00
currentChat.stopGenerating()
} else {
2023-05-01 17:13:20 -04:00
currentChat.regenerateResponse()
2023-04-08 23:28:39 -04:00
if (chatModel.count) {
if (listElement.name === qsTr("Response: ")) {
chatModel.updateCurrentResponse(index, true);
chatModel.updateStopped(index, false);
chatModel.updateThumbsUpState(index, false);
chatModel.updateThumbsDownState(index, false);
chatModel.updateNewResponse(index, "");
currentChat.prompt(listElement.prompt)
2023-04-08 23:28:39 -04:00
}
}
}
}
background: Rectangle {
border.color: myButton.down ? theme.backgroundLightest : theme.buttonBorder
border.width: 2
radius: 10
color: myButton.hovered ? theme.backgroundLighter : theme.backgroundLight
}
2023-04-20 08:31:33 -04:00
anchors.bottom: textInputView.top
anchors.horizontalCenter: textInputView.horizontalCenter
anchors.bottomMargin: 20
2023-04-08 23:28:39 -04:00
padding: 15
text: currentChat.responseInProgress ? qsTr("Stop generating") : qsTr("Regenerate response")
Accessible.description: qsTr("Controls generation of the response")
2023-04-08 23:28:39 -04:00
}
Text {
id: speed
anchors.bottom: textInputView.top
anchors.bottomMargin: 20
anchors.right: parent.right
anchors.rightMargin: 30
color: theme.mutedTextColor
text: currentChat.tokenSpeed
}
RectangularGlow {
id: effect
anchors.fill: textInputView
glowRadius: 50
spread: 0
color: theme.backgroundDark
cornerRadius: 10
opacity: 0.2
}
2023-04-20 08:31:33 -04:00
ScrollView {
id: textInputView
2023-04-08 23:28:39 -04:00
anchors.left: parent.left
anchors.right: parent.right
2023-04-08 23:28:39 -04:00
anchors.bottom: parent.bottom
anchors.margins: 30
2023-04-20 08:31:33 -04:00
height: Math.min(contentHeight, 200)
2023-05-11 16:46:25 -04:00
visible: !currentChat.isServer
2023-04-20 08:31:33 -04:00
TextArea {
id: textInput
color: theme.textColor
topPadding: 30
bottomPadding: 30
leftPadding: 20
rightPadding: 40
2023-05-11 16:46:25 -04:00
enabled: currentChat.isModelLoaded && !currentChat.isServer
wrapMode: Text.WordWrap
font.pixelSize: theme.fontSizeLarger
2023-04-20 08:31:33 -04:00
placeholderText: qsTr("Send a message...")
2023-05-20 20:02:38 -04:00
placeholderTextColor: theme.mutedTextColor
2023-04-20 08:31:33 -04:00
background: Rectangle {
color: theme.backgroundAccent
2023-04-20 08:31:33 -04:00
radius: 10
}
Accessible.role: Accessible.EditableText
Accessible.name: placeholderText
Accessible.description: qsTr("Textfield for sending messages/prompts to the model")
Keys.onReturnPressed: (event)=> {
2023-04-20 08:31:33 -04:00
if (event.modifiers & Qt.ControlModifier || event.modifiers & Qt.ShiftModifier)
event.accepted = false;
else {
2023-04-20 08:31:33 -04:00
editingFinished();
sendMessage()
}
2023-04-08 23:28:39 -04:00
}
function sendMessage() {
2023-04-20 08:31:33 -04:00
if (textInput.text === "")
return
2023-05-01 17:13:20 -04:00
currentChat.stopGenerating()
currentChat.newPromptResponsePair(textInput.text);
currentChat.prompt(textInput.text,
MySettings.promptTemplate,
MySettings.maxLength,
MySettings.topK,
MySettings.topP,
MySettings.temperature,
MySettings.promptBatchSize,
MySettings.repeatPenalty,
MySettings.repeatPenaltyTokens)
2023-04-20 08:31:33 -04:00
textInput.text = ""
2023-04-08 23:28:39 -04:00
}
2023-04-20 08:31:33 -04:00
}
}
2023-04-08 23:28:39 -04:00
MyToolButton {
2023-04-20 08:31:33 -04:00
anchors.right: textInputView.right
anchors.verticalCenter: textInputView.verticalCenter
anchors.rightMargin: 15
width: 30
height: 30
2023-05-11 16:46:25 -04:00
visible: !currentChat.isServer
source: "qrc:/gpt4all/icons/send_message.svg"
2023-04-20 08:31:33 -04:00
Accessible.name: qsTr("Send the message button")
Accessible.description: qsTr("Sends the message/prompt contained in textfield to the model")
onClicked: {
textInput.sendMessage()
2023-04-08 23:28:39 -04:00
}
}
}
}