mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-25 23:13:06 +00:00
Add context link to references.
This commit is contained in:
parent
f3dc031a9d
commit
0a4c3a14ca
@ -205,12 +205,13 @@ void Chat::responseStopped()
|
|||||||
{
|
{
|
||||||
const QString chatResponse = response();
|
const QString chatResponse = response();
|
||||||
QList<QString> references;
|
QList<QString> references;
|
||||||
|
QList<QString> referencesContext;
|
||||||
int validReferenceNumber = 1;
|
int validReferenceNumber = 1;
|
||||||
for (const ResultInfo &info : m_results) {
|
for (const ResultInfo &info : m_results) {
|
||||||
if (info.file.isEmpty())
|
if (info.file.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (validReferenceNumber == 1)
|
if (validReferenceNumber == 1)
|
||||||
references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("---"));
|
references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("\n---"));
|
||||||
QString reference;
|
QString reference;
|
||||||
{
|
{
|
||||||
QTextStream stream(&reference);
|
QTextStream stream(&reference);
|
||||||
@ -230,12 +231,14 @@ void Chat::responseStopped()
|
|||||||
stream << "-" << info.to;
|
stream << "-" << info.to;
|
||||||
stream << ". ";
|
stream << ". ";
|
||||||
}
|
}
|
||||||
|
stream << "[Context](context://" << validReferenceNumber - 1 << ")";
|
||||||
}
|
}
|
||||||
references.append(reference);
|
references.append(reference);
|
||||||
|
referencesContext.append(info.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int index = m_chatModel->count() - 1;
|
const int index = m_chatModel->count() - 1;
|
||||||
m_chatModel->updateReferences(index, references.join("\n"));
|
m_chatModel->updateReferences(index, references.join("\n"), referencesContext);
|
||||||
emit responseChanged();
|
emit responseChanged();
|
||||||
|
|
||||||
m_results.clear();
|
m_results.clear();
|
||||||
|
@ -18,6 +18,7 @@ struct ChatItem
|
|||||||
Q_PROPERTY(bool thumbsUpState MEMBER thumbsUpState)
|
Q_PROPERTY(bool thumbsUpState MEMBER thumbsUpState)
|
||||||
Q_PROPERTY(bool thumbsDownState MEMBER thumbsDownState)
|
Q_PROPERTY(bool thumbsDownState MEMBER thumbsDownState)
|
||||||
Q_PROPERTY(QString references MEMBER references)
|
Q_PROPERTY(QString references MEMBER references)
|
||||||
|
Q_PROPERTY(QList<QString> referencesContext MEMBER referencesContext)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int id = 0;
|
int id = 0;
|
||||||
@ -26,6 +27,7 @@ public:
|
|||||||
QString prompt;
|
QString prompt;
|
||||||
QString newResponse;
|
QString newResponse;
|
||||||
QString references;
|
QString references;
|
||||||
|
QList<QString> referencesContext;
|
||||||
bool currentResponse = false;
|
bool currentResponse = false;
|
||||||
bool stopped = false;
|
bool stopped = false;
|
||||||
bool thumbsUpState = false;
|
bool thumbsUpState = false;
|
||||||
@ -51,7 +53,8 @@ public:
|
|||||||
StoppedRole,
|
StoppedRole,
|
||||||
ThumbsUpStateRole,
|
ThumbsUpStateRole,
|
||||||
ThumbsDownStateRole,
|
ThumbsDownStateRole,
|
||||||
ReferencesRole
|
ReferencesRole,
|
||||||
|
ReferencesContextRole
|
||||||
};
|
};
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
||||||
@ -87,6 +90,8 @@ public:
|
|||||||
return item.thumbsDownState;
|
return item.thumbsDownState;
|
||||||
case ReferencesRole:
|
case ReferencesRole:
|
||||||
return item.references;
|
return item.references;
|
||||||
|
case ReferencesContextRole:
|
||||||
|
return item.referencesContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -105,6 +110,7 @@ public:
|
|||||||
roles[ThumbsUpStateRole] = "thumbsUpState";
|
roles[ThumbsUpStateRole] = "thumbsUpState";
|
||||||
roles[ThumbsDownStateRole] = "thumbsDownState";
|
roles[ThumbsDownStateRole] = "thumbsDownState";
|
||||||
roles[ReferencesRole] = "references";
|
roles[ReferencesRole] = "references";
|
||||||
|
roles[ReferencesContextRole] = "referencesContext";
|
||||||
return roles;
|
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;
|
if (index < 0 || index >= m_chatItems.size()) return;
|
||||||
|
|
||||||
@ -190,6 +196,10 @@ public:
|
|||||||
item.references = references;
|
item.references = references;
|
||||||
emit dataChanged(createIndex(index, 0), createIndex(index, 0), {ReferencesRole});
|
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)
|
Q_INVOKABLE void updateThumbsUpState(int index, bool b)
|
||||||
@ -240,8 +250,10 @@ public:
|
|||||||
stream << c.stopped;
|
stream << c.stopped;
|
||||||
stream << c.thumbsUpState;
|
stream << c.thumbsUpState;
|
||||||
stream << c.thumbsDownState;
|
stream << c.thumbsDownState;
|
||||||
if (version > 2)
|
if (version > 2) {
|
||||||
stream << c.references;
|
stream << c.references;
|
||||||
|
stream << c.referencesContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return stream.status() == QDataStream::Ok;
|
return stream.status() == QDataStream::Ok;
|
||||||
}
|
}
|
||||||
@ -261,8 +273,10 @@ public:
|
|||||||
stream >> c.stopped;
|
stream >> c.stopped;
|
||||||
stream >> c.thumbsUpState;
|
stream >> c.thumbsUpState;
|
||||||
stream >> c.thumbsDownState;
|
stream >> c.thumbsDownState;
|
||||||
if (version > 2)
|
if (version > 2) {
|
||||||
stream >> c.references;
|
stream >> c.references;
|
||||||
|
stream >> c.referencesContext;
|
||||||
|
}
|
||||||
beginInsertRows(QModelIndex(), m_chatItems.size(), m_chatItems.size());
|
beginInsertRows(QModelIndex(), m_chatItems.size(), m_chatItems.size());
|
||||||
m_chatItems.append(c);
|
m_chatItems.append(c);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
@ -555,6 +555,14 @@ Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopupDialog {
|
||||||
|
id: referenceContextDialog
|
||||||
|
anchors.centerIn: parent
|
||||||
|
shouldTimeOut: false
|
||||||
|
shouldShowBusy: false
|
||||||
|
modal: true
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: conversation
|
id: conversation
|
||||||
color: theme.backgroundLight
|
color: theme.backgroundLight
|
||||||
@ -600,6 +608,7 @@ Window {
|
|||||||
width: listView.width
|
width: listView.width
|
||||||
color: theme.textColor
|
color: theme.textColor
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
textFormat: TextEdit.MarkdownText
|
||||||
focus: false
|
focus: false
|
||||||
readOnly: true
|
readOnly: true
|
||||||
font.pixelSize: theme.fontSizeLarge
|
font.pixelSize: theme.fontSizeLarge
|
||||||
@ -621,6 +630,17 @@ Window {
|
|||||||
leftPadding: 100
|
leftPadding: 100
|
||||||
rightPadding: 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 {
|
Item {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 90
|
anchors.leftMargin: 90
|
||||||
|
@ -27,8 +27,12 @@ Dialog {
|
|||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: textField
|
id: textField
|
||||||
anchors.verticalCenter: busyIndicator.verticalCenter
|
width: Math.min(1024, implicitWidth)
|
||||||
horizontalAlignment: Text.AlignJustify
|
height: Math.min(600, implicitHeight)
|
||||||
|
anchors.verticalCenter: shouldShowBusy ? busyIndicator.verticalCenter : parent.verticalCenter
|
||||||
|
horizontalAlignment: Text.AlignLeft
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
color: theme.textColor
|
color: theme.textColor
|
||||||
Accessible.role: Accessible.HelpBalloon
|
Accessible.role: Accessible.HelpBalloon
|
||||||
Accessible.name: text
|
Accessible.name: text
|
||||||
|
Loading…
Reference in New Issue
Block a user