diff --git a/gpt4all-chat/chat.cpp b/gpt4all-chat/chat.cpp index f9ef8b5c..2e95f62e 100644 --- a/gpt4all-chat/chat.cpp +++ b/gpt4all-chat/chat.cpp @@ -204,13 +204,13 @@ void Chat::promptProcessing() void Chat::responseStopped() { const QString chatResponse = response(); - QList finalResponse { chatResponse }; + QList references; int validReferenceNumber = 1; for (const ResultInfo &info : m_results) { if (info.file.isEmpty()) continue; if (validReferenceNumber == 1) - finalResponse.append(QStringLiteral("---")); + references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("---")); QString reference; { QTextStream stream(&reference); @@ -231,11 +231,11 @@ void Chat::responseStopped() stream << ". "; } } - finalResponse.append(reference); + references.append(reference); } const int index = m_chatModel->count() - 1; - m_chatModel->updateValue(index, finalResponse.join("\n")); + m_chatModel->updateReferences(index, references.join("\n")); emit responseChanged(); m_results.clear(); diff --git a/gpt4all-chat/chatmodel.h b/gpt4all-chat/chatmodel.h index e3c01a9a..a5a53326 100644 --- a/gpt4all-chat/chatmodel.h +++ b/gpt4all-chat/chatmodel.h @@ -17,6 +17,7 @@ struct ChatItem Q_PROPERTY(bool stopped MEMBER stopped) Q_PROPERTY(bool thumbsUpState MEMBER thumbsUpState) Q_PROPERTY(bool thumbsDownState MEMBER thumbsDownState) + Q_PROPERTY(QString references MEMBER references) public: int id = 0; @@ -24,6 +25,7 @@ public: QString value; QString prompt; QString newResponse; + QString references; bool currentResponse = false; bool stopped = false; bool thumbsUpState = false; @@ -48,7 +50,8 @@ public: CurrentResponseRole, StoppedRole, ThumbsUpStateRole, - ThumbsDownStateRole + ThumbsDownStateRole, + ReferencesRole }; int rowCount(const QModelIndex &parent = QModelIndex()) const override @@ -82,6 +85,8 @@ public: return item.thumbsUpState; case ThumbsDownStateRole: return item.thumbsDownState; + case ReferencesRole: + return item.references; } return QVariant(); @@ -99,6 +104,7 @@ public: roles[StoppedRole] = "stopped"; roles[ThumbsUpStateRole] = "thumbsUpState"; roles[ThumbsDownStateRole] = "thumbsDownState"; + roles[ReferencesRole] = "references"; return roles; } @@ -175,6 +181,17 @@ public: } } + Q_INVOKABLE void updateReferences(int index, const QString &references) + { + if (index < 0 || index >= m_chatItems.size()) return; + + ChatItem &item = m_chatItems[index]; + if (item.references != references) { + item.references = references; + emit dataChanged(createIndex(index, 0), createIndex(index, 0), {ReferencesRole}); + } + } + Q_INVOKABLE void updateThumbsUpState(int index, bool b) { if (index < 0 || index >= m_chatItems.size()) return; @@ -223,6 +240,8 @@ public: stream << c.stopped; stream << c.thumbsUpState; stream << c.thumbsDownState; + if (version > 2) + stream << c.references; } return stream.status() == QDataStream::Ok; } @@ -242,6 +261,8 @@ public: stream >> c.stopped; stream >> c.thumbsUpState; stream >> c.thumbsDownState; + if (version > 2) + stream >> c.references; beginInsertRows(QModelIndex(), m_chatItems.size(), m_chatItems.size()); m_chatItems.append(c); endInsertRows(); diff --git a/gpt4all-chat/main.qml b/gpt4all-chat/main.qml index 305794ca..f01b540a 100644 --- a/gpt4all-chat/main.qml +++ b/gpt4all-chat/main.qml @@ -596,7 +596,7 @@ Window { Accessible.description: qsTr("This is the list of prompt/response pairs comprising the actual conversation with the model") delegate: TextArea { - text: value + text: value + references width: listView.width color: theme.textColor wrapMode: Text.WordWrap