Add context link to references.

pull/721/head
Adam Treat 1 year ago committed by AT
parent db9eecdce4
commit 9b0629db8b

@ -205,12 +205,13 @@ void Chat::responseStopped()
{
const QString chatResponse = response();
QList<QString> references;
QList<QString> referencesContext;
int validReferenceNumber = 1;
for (const ResultInfo &info : m_results) {
if (info.file.isEmpty())
continue;
if (validReferenceNumber == 1)
references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("---"));
references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("\n---"));
QString reference;
{
QTextStream stream(&reference);
@ -230,12 +231,14 @@ void Chat::responseStopped()
stream << "-" << info.to;
stream << ". ";
}
stream << "[Context](context://" << validReferenceNumber - 1 << ")";
}
references.append(reference);
referencesContext.append(info.text);
}
const int index = m_chatModel->count() - 1;
m_chatModel->updateReferences(index, references.join("\n"));
m_chatModel->updateReferences(index, references.join("\n"), referencesContext);
emit responseChanged();
m_results.clear();

@ -18,6 +18,7 @@ struct ChatItem
Q_PROPERTY(bool thumbsUpState MEMBER thumbsUpState)
Q_PROPERTY(bool thumbsDownState MEMBER thumbsDownState)
Q_PROPERTY(QString references MEMBER references)
Q_PROPERTY(QList<QString> referencesContext MEMBER referencesContext)
public:
int id = 0;
@ -26,6 +27,7 @@ public:
QString prompt;
QString newResponse;
QString references;
QList<QString> referencesContext;
bool currentResponse = false;
bool stopped = false;
bool thumbsUpState = false;
@ -51,7 +53,8 @@ public:
StoppedRole,
ThumbsUpStateRole,
ThumbsDownStateRole,
ReferencesRole
ReferencesRole,
ReferencesContextRole
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override
@ -87,6 +90,8 @@ public:
return item.thumbsDownState;
case ReferencesRole:
return item.references;
case ReferencesContextRole:
return item.referencesContext;
}
return QVariant();
@ -105,6 +110,7 @@ public:
roles[ThumbsUpStateRole] = "thumbsUpState";
roles[ThumbsDownStateRole] = "thumbsDownState";
roles[ReferencesRole] = "references";
roles[ReferencesContextRole] = "referencesContext";
return roles;
}
@ -181,7 +187,7 @@ public:
}
}
Q_INVOKABLE void updateReferences(int index, const QString &references)
Q_INVOKABLE void updateReferences(int index, const QString &references, const QList<QString> &referencesContext)
{
if (index < 0 || index >= m_chatItems.size()) return;
@ -190,6 +196,10 @@ public:
item.references = references;
emit dataChanged(createIndex(index, 0), createIndex(index, 0), {ReferencesRole});
}
if (item.referencesContext != referencesContext) {
item.referencesContext = referencesContext;
emit dataChanged(createIndex(index, 0), createIndex(index, 0), {ReferencesContextRole});
}
}
Q_INVOKABLE void updateThumbsUpState(int index, bool b)
@ -240,8 +250,10 @@ public:
stream << c.stopped;
stream << c.thumbsUpState;
stream << c.thumbsDownState;
if (version > 2)
if (version > 2) {
stream << c.references;
stream << c.referencesContext;
}
}
return stream.status() == QDataStream::Ok;
}
@ -261,8 +273,10 @@ public:
stream >> c.stopped;
stream >> c.thumbsUpState;
stream >> c.thumbsDownState;
if (version > 2)
if (version > 2) {
stream >> c.references;
stream >> c.referencesContext;
}
beginInsertRows(QModelIndex(), m_chatItems.size(), m_chatItems.size());
m_chatItems.append(c);
endInsertRows();

@ -555,6 +555,14 @@ Window {
}
}
PopupDialog {
id: referenceContextDialog
anchors.centerIn: parent
shouldTimeOut: false
shouldShowBusy: false
modal: true
}
Rectangle {
id: conversation
color: theme.backgroundLight
@ -600,6 +608,7 @@ Window {
width: listView.width
color: theme.textColor
wrapMode: Text.WordWrap
textFormat: TextEdit.MarkdownText
focus: false
readOnly: true
font.pixelSize: theme.fontSizeLarge
@ -621,6 +630,17 @@ Window {
leftPadding: 100
rightPadding: 100
onLinkActivated: function (link) {
if (!link.startsWith("context://"))
return;
console.log("link " + link);
var integer = parseInt(link.split("://")[1]);
console.log("context is" + referencesContext[integer - 1]);
referenceContextDialog.text = referencesContext[integer - 1];
referenceContextDialog.open();
}
Item {
anchors.left: parent.left
anchors.leftMargin: 90

@ -27,8 +27,12 @@ Dialog {
Text {
id: textField
anchors.verticalCenter: busyIndicator.verticalCenter
horizontalAlignment: Text.AlignJustify
width: Math.min(1024, implicitWidth)
height: Math.min(600, implicitHeight)
anchors.verticalCenter: shouldShowBusy ? busyIndicator.verticalCenter : parent.verticalCenter
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
color: theme.textColor
Accessible.role: Accessible.HelpBalloon
Accessible.name: text

Loading…
Cancel
Save