Store the references separately so they are not sent to datalake.

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

@ -204,13 +204,13 @@ void Chat::promptProcessing()
void Chat::responseStopped() void Chat::responseStopped()
{ {
const QString chatResponse = response(); const QString chatResponse = response();
QList<QString> finalResponse { chatResponse }; QList<QString> references;
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)
finalResponse.append(QStringLiteral("---")); references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("---"));
QString reference; QString reference;
{ {
QTextStream stream(&reference); QTextStream stream(&reference);
@ -231,11 +231,11 @@ void Chat::responseStopped()
stream << ". "; stream << ". ";
} }
} }
finalResponse.append(reference); references.append(reference);
} }
const int index = m_chatModel->count() - 1; const int index = m_chatModel->count() - 1;
m_chatModel->updateValue(index, finalResponse.join("\n")); m_chatModel->updateReferences(index, references.join("\n"));
emit responseChanged(); emit responseChanged();
m_results.clear(); m_results.clear();

@ -17,6 +17,7 @@ struct ChatItem
Q_PROPERTY(bool stopped MEMBER stopped) Q_PROPERTY(bool stopped MEMBER stopped)
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)
public: public:
int id = 0; int id = 0;
@ -24,6 +25,7 @@ public:
QString value; QString value;
QString prompt; QString prompt;
QString newResponse; QString newResponse;
QString references;
bool currentResponse = false; bool currentResponse = false;
bool stopped = false; bool stopped = false;
bool thumbsUpState = false; bool thumbsUpState = false;
@ -48,7 +50,8 @@ public:
CurrentResponseRole, CurrentResponseRole,
StoppedRole, StoppedRole,
ThumbsUpStateRole, ThumbsUpStateRole,
ThumbsDownStateRole ThumbsDownStateRole,
ReferencesRole
}; };
int rowCount(const QModelIndex &parent = QModelIndex()) const override int rowCount(const QModelIndex &parent = QModelIndex()) const override
@ -82,6 +85,8 @@ public:
return item.thumbsUpState; return item.thumbsUpState;
case ThumbsDownStateRole: case ThumbsDownStateRole:
return item.thumbsDownState; return item.thumbsDownState;
case ReferencesRole:
return item.references;
} }
return QVariant(); return QVariant();
@ -99,6 +104,7 @@ public:
roles[StoppedRole] = "stopped"; roles[StoppedRole] = "stopped";
roles[ThumbsUpStateRole] = "thumbsUpState"; roles[ThumbsUpStateRole] = "thumbsUpState";
roles[ThumbsDownStateRole] = "thumbsDownState"; roles[ThumbsDownStateRole] = "thumbsDownState";
roles[ReferencesRole] = "references";
return roles; 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) Q_INVOKABLE void updateThumbsUpState(int index, bool b)
{ {
if (index < 0 || index >= m_chatItems.size()) return; if (index < 0 || index >= m_chatItems.size()) return;
@ -223,6 +240,8 @@ public:
stream << c.stopped; stream << c.stopped;
stream << c.thumbsUpState; stream << c.thumbsUpState;
stream << c.thumbsDownState; stream << c.thumbsDownState;
if (version > 2)
stream << c.references;
} }
return stream.status() == QDataStream::Ok; return stream.status() == QDataStream::Ok;
} }
@ -242,6 +261,8 @@ public:
stream >> c.stopped; stream >> c.stopped;
stream >> c.thumbsUpState; stream >> c.thumbsUpState;
stream >> c.thumbsDownState; stream >> c.thumbsDownState;
if (version > 2)
stream >> c.references;
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();

@ -596,7 +596,7 @@ Window {
Accessible.description: qsTr("This is the list of prompt/response pairs comprising the actual conversation with the model") Accessible.description: qsTr("This is the list of prompt/response pairs comprising the actual conversation with the model")
delegate: TextArea { delegate: TextArea {
text: value text: value + references
width: listView.width width: listView.width
color: theme.textColor color: theme.textColor
wrapMode: Text.WordWrap wrapMode: Text.WordWrap

Loading…
Cancel
Save