Warning, /utilities/alpaka/src/apps/qml/ChatView.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Loren Burkholder <computersemiexpert@outlook.com>
0002 // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005
0006 import QtQuick
0007 import QtQuick.Controls as Controls
0008 import QtQuick.Layouts
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.coreaddons as KCoreAddons
0011 import org.kde.kirigamiaddons.components as KirigamiComponents
0012 import org.kde.alpaka
0013
0014 Kirigami.Page {
0015 title: i18n("Alpaka")
0016 actions: [
0017 Kirigami.Action {
0018 text: i18n("Start over")
0019 icon.name: "view-refresh"
0020 onTriggered: chat.resetConversation()
0021 },
0022 Kirigami.Action {
0023 text: i18n("Settings")
0024 icon.name: "settings-configure"
0025 onTriggered: pageStack.pushDialogLayer(settingsPage)
0026 }
0027 ]
0028
0029 header: KirigamiComponents.Banner {
0030 id: errorBanner
0031
0032 visible: chat.llm.hasError
0033 type: Kirigami.MessageType.Error
0034 width: parent.width
0035 actions: [
0036 Kirigami.Action {
0037 text: i18n("Try again")
0038 icon.name: "view-refresh"
0039 onTriggered: chat.llm.reload()
0040 }
0041 ]
0042 }
0043
0044 Kirigami.PlaceholderMessage {
0045 anchors.centerIn: parent
0046
0047 text: i18n("Waiting for interface")
0048 visible: !chat.llm.ready
0049 }
0050
0051 ColumnLayout {
0052 spacing: 10
0053 anchors.fill: parent
0054
0055 Controls.ScrollView {
0056 Layout.fillWidth: true
0057 Layout.fillHeight: true
0058
0059 ListView {
0060 id: chatView
0061 spacing: 10
0062 model: chat
0063 clip: true
0064
0065 delegate: RowLayout {
0066 id: messageDelegate
0067
0068 required property string message
0069 required property var sender
0070 required property bool finished
0071
0072 width: chatView.width
0073 height: messageBubble.height
0074
0075 Rectangle {
0076 id: messageBubble
0077
0078 radius: 5
0079 color: palette.alternateBase
0080 Layout.preferredWidth: messageLayout.implicitWidth + 20
0081 Layout.preferredHeight: messageLayout.implicitHeight + 20
0082 Layout.maximumWidth: chatView.width * 0.75
0083 Layout.alignment: messageDelegate.sender === ChatModel.LLM ? Qt.AlignLeft : Qt.AlignRight
0084 border {
0085 width: 1
0086 color: palette.highlight
0087 }
0088
0089 ColumnLayout {
0090 id: messageLayout
0091
0092 anchors.fill: parent
0093 anchors.margins: 10
0094 spacing: 10
0095
0096 RowLayout {
0097 Layout.fillWidth: true
0098 spacing: 10
0099
0100 KirigamiComponents.Avatar {
0101 source: messageDelegate.sender === ChatModel.User ? localUser.faceIconUrl + "?timestamp=" + Date.now() : ""
0102 Layout.preferredHeight: userName.height + 15
0103 Layout.preferredWidth: height
0104 }
0105
0106 Controls.Label {
0107 id: userName
0108
0109 text: messageDelegate.sender === ChatModel.LLM ? i18n("Alpaka") : localUser.fullName
0110 font.bold: true
0111 font.pixelSize: 15
0112 }
0113
0114 TypingIndicator {
0115 visible: !messageDelegate.finished
0116 }
0117 }
0118
0119 Controls.Label {
0120 text: messageDelegate.message
0121 wrapMode: Controls.Label.WordWrap
0122 Layout.fillWidth: true
0123 textFormat: Controls.Label.MarkdownText
0124 }
0125 }
0126 }
0127 }
0128 }
0129 }
0130
0131 Controls.TextField {
0132 id: messageInput
0133
0134 placeholderText: i18n("Enter a message")
0135 enabled: chat.llm.ready && !chat.replyInProgress
0136 Layout.fillWidth: true
0137 focus: true
0138 onAccepted: {
0139 chat.sendMessage(messageInput.text);
0140 messageInput.text = "";
0141 }
0142 }
0143 }
0144 }