Fix typo and add new show references setting to localdocs.

This commit is contained in:
Adam Treat 2023-07-05 19:41:07 -04:00
parent 8dcf68dbf4
commit eab92a9d73
6 changed files with 90 additions and 43 deletions

View File

@ -189,43 +189,45 @@ void Chat::responseStopped()
m_tokenSpeed = QString();
emit tokenSpeedChanged();
const QString chatResponse = response();
QList<QString> references;
QList<QString> referencesContext;
int validReferenceNumber = 1;
for (const ResultInfo &info : databaseResults()) {
if (info.file.isEmpty())
continue;
if (validReferenceNumber == 1)
references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("\n---"));
QString reference;
{
QTextStream stream(&reference);
stream << (validReferenceNumber++) << ". ";
if (!info.title.isEmpty())
stream << "\"" << info.title << "\". ";
if (!info.author.isEmpty())
stream << "By " << info.author << ". ";
if (!info.date.isEmpty())
stream << "Date: " << info.date << ". ";
stream << "In " << info.file << ". ";
if (info.page != -1)
stream << "Page " << info.page << ". ";
if (info.from != -1) {
stream << "Lines " << info.from;
if (info.to != -1)
stream << "-" << info.to;
stream << ". ";
if (MySettings::globalInstance()->localDocsShowReferences()) {
const QString chatResponse = response();
QList<QString> references;
QList<QString> referencesContext;
int validReferenceNumber = 1;
for (const ResultInfo &info : databaseResults()) {
if (info.file.isEmpty())
continue;
if (validReferenceNumber == 1)
references.append((!chatResponse.endsWith("\n") ? "\n" : QString()) + QStringLiteral("\n---"));
QString reference;
{
QTextStream stream(&reference);
stream << (validReferenceNumber++) << ". ";
if (!info.title.isEmpty())
stream << "\"" << info.title << "\". ";
if (!info.author.isEmpty())
stream << "By " << info.author << ". ";
if (!info.date.isEmpty())
stream << "Date: " << info.date << ". ";
stream << "In " << info.file << ". ";
if (info.page != -1)
stream << "Page " << info.page << ". ";
if (info.from != -1) {
stream << "Lines " << info.from;
if (info.to != -1)
stream << "-" << info.to;
stream << ". ";
}
stream << "[Context](context://" << validReferenceNumber - 1 << ")";
}
stream << "[Context](context://" << validReferenceNumber - 1 << ")";
references.append(reference);
referencesContext.append(info.text);
}
references.append(reference);
referencesContext.append(info.text);
}
const int index = m_chatModel->count() - 1;
m_chatModel->updateReferences(index, references.join("\n"), referencesContext);
emit responseChanged();
const int index = m_chatModel->count() - 1;
m_chatModel->updateReferences(index, references.join("\n"), referencesContext);
emit responseChanged();
}
m_responseInProgress = false;
m_responseState = Chat::ResponseStopped;

View File

@ -164,7 +164,7 @@
"parameters": "13 billion",
"quant": "q4_2",
"type": "LLaMA",
"description": "<strong>Trained with RHLF by Stability AI</strong><br><ul><li>Instruction based<li>Cannot be used commercially</ul>",
"description": "<strong>Trained with RLHF by Stability AI</strong><br><ul><li>Instruction based<li>Cannot be used commercially</ul>",
"systemPrompt": "## Assistant: I am StableVicuna, a large language model created by CarperAI. I am here to chat!\n\n"
},
{

View File

@ -17,6 +17,7 @@ static bool default_forceMetal = false;
static QString default_lastVersionStarted = "";
static int default_localDocsChunkSize = 256;
static int default_localDocsRetrievalSize = 3;
static bool default_localDocsShowReferences = true;
static QString default_networkAttribution = "";
static bool default_networkIsActive = false;
static bool default_networkUsageStatsActive = false;
@ -89,6 +90,7 @@ void MySettings::restoreLocalDocsDefaults()
{
setLocalDocsChunkSize(default_localDocsChunkSize);
setLocalDocsRetrievalSize(default_localDocsRetrievalSize);
setLocalDocsShowReferences(default_localDocsShowReferences);
}
void MySettings::eraseModel(const ModelInfo &m)
@ -520,6 +522,24 @@ void MySettings::setLocalDocsRetrievalSize(int s)
emit localDocsRetrievalSizeChanged();
}
bool MySettings::localDocsShowReferences() const
{
QSettings setting;
setting.sync();
return setting.value("localdocs/showReferences", default_localDocsShowReferences).toBool();
}
void MySettings::setLocalDocsShowReferences(bool b)
{
if (localDocsShowReferences() == b)
return;
QSettings setting;
setting.setValue("localdocs/showReferences", b);
setting.sync();
emit localDocsShowReferencesChanged();
}
QString MySettings::networkAttribution() const
{
QSettings setting;

View File

@ -19,6 +19,7 @@ class MySettings : public QObject
Q_PROPERTY(QString lastVersionStarted READ lastVersionStarted WRITE setLastVersionStarted NOTIFY lastVersionStartedChanged)
Q_PROPERTY(int localDocsChunkSize READ localDocsChunkSize WRITE setLocalDocsChunkSize NOTIFY localDocsChunkSizeChanged)
Q_PROPERTY(int localDocsRetrievalSize READ localDocsRetrievalSize WRITE setLocalDocsRetrievalSize NOTIFY localDocsRetrievalSizeChanged)
Q_PROPERTY(bool localDocsShowReferences READ localDocsShowReferences WRITE setLocalDocsShowReferences NOTIFY localDocsShowReferencesChanged)
Q_PROPERTY(QString networkAttribution READ networkAttribution WRITE setNetworkAttribution NOTIFY networkAttributionChanged)
Q_PROPERTY(bool networkIsActive READ networkIsActive WRITE setNetworkIsActive NOTIFY networkIsActiveChanged)
Q_PROPERTY(bool networkUsageStatsActive READ networkUsageStatsActive WRITE setNetworkUsageStatsActive NOTIFY networkUsageStatsActiveChanged)
@ -81,6 +82,8 @@ public:
void setLocalDocsChunkSize(int s);
int localDocsRetrievalSize() const;
void setLocalDocsRetrievalSize(int s);
bool localDocsShowReferences() const;
void setLocalDocsShowReferences(bool b);
// Network settings
QString networkAttribution() const;
@ -112,6 +115,7 @@ Q_SIGNALS:
void lastVersionStartedChanged();
void localDocsChunkSizeChanged();
void localDocsRetrievalSizeChanged();
void localDocsShowReferencesChanged();
void networkAttributionChanged();
void networkIsActiveChanged();
void networkUsageStatsActiveChanged();

View File

@ -170,6 +170,23 @@ MySettingsTab {
}
}
RowLayout {
Label {
id: showReferencesLabel
text: qsTr("Show references:")
color: theme.textColor
}
MyCheckBox {
id: showReferencesBox
checked: MySettings.localDocsShowReferences
onClicked: {
MySettings.localDocsShowReferences = !MySettings.localDocsShowReferences
}
ToolTip.text: qsTr("Shows any references in GUI generated by localdocs")
ToolTip.visible: hovered
}
}
Rectangle {
Layout.fillWidth: true
height: 1

View File

@ -351,10 +351,12 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
message.insert("role", "assistant");
message.insert("content", result);
choice.insert("message", message);
QJsonArray references;
for (const auto &ref : infos)
references.append(resultToJson(ref));
choice.insert("references", references);
if (MySettings::globalInstance()->localDocsShowReferences()) {
QJsonArray references;
for (const auto &ref : infos)
references.append(resultToJson(ref));
choice.insert("references", references);
}
choices.append(choice);
}
} else {
@ -367,10 +369,12 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
choice.insert("index", index++);
choice.insert("logprobs", QJsonValue::Null); // We don't support
choice.insert("finish_reason", responseTokens == max_tokens ? "length" : "stop");
QJsonArray references;
for (const auto &ref : infos)
references.append(resultToJson(ref));
choice.insert("references", references);
if (MySettings::globalInstance()->localDocsShowReferences()) {
QJsonArray references;
for (const auto &ref : infos)
references.append(resultToJson(ref));
choice.insert("references", references);
}
choices.append(choice);
}
}