mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2024-10-01 01:06:10 -04:00
Perform a health check on the datalake before we enable network.
This commit is contained in:
parent
c366fc8054
commit
3ef96b3ec5
26
main.qml
26
main.qml
@ -192,11 +192,17 @@ Window {
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
featureComingSoon.open()
|
||||
// if (Network.isActive)
|
||||
// Network.isActive = false
|
||||
// else
|
||||
// networkDialog.open()
|
||||
if (Network.isActive)
|
||||
Network.isActive = false
|
||||
else
|
||||
networkDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Network
|
||||
function onHealthCheckFailed(code) {
|
||||
healthCheckFailed.open();
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,9 +243,9 @@ Window {
|
||||
}
|
||||
|
||||
PopupDialog {
|
||||
id: featureComingSoon
|
||||
id: healthCheckFailed
|
||||
anchors.centerIn: parent
|
||||
text: qsTr("Feature coming soon!")
|
||||
text: qsTr("Connection to datalake failed.")
|
||||
}
|
||||
|
||||
Button {
|
||||
@ -278,12 +284,6 @@ Window {
|
||||
copyEdit.selectAll()
|
||||
copyEdit.copy()
|
||||
copyMessage.open()
|
||||
timer.start()
|
||||
}
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 500; running: false; repeat: false
|
||||
onTriggered: copyMessage.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
37
network.cpp
37
network.cpp
@ -24,11 +24,10 @@ Network::Network()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.sync();
|
||||
m_isActive = settings.value("network/isActive", false).toBool();
|
||||
m_uniqueId = settings.value("uniqueId", generateUniqueId()).toString();
|
||||
settings.setValue("uniqueId", m_uniqueId);
|
||||
settings.sync();
|
||||
emit activeChanged();
|
||||
setActive(settings.value("network/isActive", false).toBool());
|
||||
}
|
||||
|
||||
void Network::setActive(bool b)
|
||||
@ -38,6 +37,8 @@ void Network::setActive(bool b)
|
||||
settings.sync();
|
||||
m_isActive = b;
|
||||
emit activeChanged();
|
||||
if (m_isActive)
|
||||
sendHealth();
|
||||
}
|
||||
|
||||
QString Network::generateUniqueId() const
|
||||
@ -101,8 +102,10 @@ void Network::handleJsonUploadFinished()
|
||||
int code = response.toInt(&ok);
|
||||
if (!ok)
|
||||
qWarning() << "ERROR: Invalid response.";
|
||||
if (code != 200)
|
||||
if (code != 200) {
|
||||
qWarning() << "ERROR: response != 200 code:" << code;
|
||||
sendHealth();
|
||||
}
|
||||
|
||||
QByteArray jsonData = jsonReply->readAll();
|
||||
QJsonParseError err;
|
||||
@ -124,3 +127,31 @@ bool Network::sendConversation(const QString &conversation)
|
||||
{
|
||||
return packageAndSendJson(conversation);
|
||||
}
|
||||
|
||||
void Network::sendHealth()
|
||||
{
|
||||
QUrl healthUrl("http://localhost/v1/health");
|
||||
QNetworkRequest request(healthUrl);
|
||||
QNetworkReply *healthReply = m_networkManager.get(request);
|
||||
connect(healthReply, &QNetworkReply::finished, this, &Network::handleHealthFinished);
|
||||
}
|
||||
|
||||
void Network::handleHealthFinished()
|
||||
{
|
||||
QNetworkReply *healthReply = qobject_cast<QNetworkReply *>(sender());
|
||||
if (!healthReply)
|
||||
return;
|
||||
|
||||
QVariant response = healthReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
Q_ASSERT(response.isValid());
|
||||
bool ok;
|
||||
int code = response.toInt(&ok);
|
||||
if (!ok)
|
||||
qWarning() << "ERROR: Invalid response.";
|
||||
if (code != 200) {
|
||||
qWarning() << "ERROR: response != 200 code:" << code;
|
||||
emit healthCheckFailed(code);
|
||||
setActive(false);
|
||||
}
|
||||
healthReply->deleteLater();
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ class Network : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isActive READ isActive WRITE setActive NOTIFY activeChanged)
|
||||
public:
|
||||
|
||||
static Network *globalInstance();
|
||||
|
||||
bool isActive() const { return m_isActive; }
|
||||
@ -21,11 +20,14 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void activeChanged();
|
||||
void healthCheckFailed(int code);
|
||||
|
||||
private Q_SLOTS:
|
||||
void handleHealthFinished();
|
||||
void handleJsonUploadFinished();
|
||||
|
||||
private:
|
||||
void sendHealth();
|
||||
bool packageAndSendJson(const QString &json);
|
||||
|
||||
private:
|
||||
|
@ -4,7 +4,7 @@ import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Dialog {
|
||||
id: copyMessage
|
||||
id: popupDialog
|
||||
anchors.centerIn: parent
|
||||
modal: false
|
||||
opacity: 0.9
|
||||
@ -29,4 +29,14 @@ Dialog {
|
||||
exit: Transition {
|
||||
NumberAnimation { duration: 500; property: "opacity"; from: 1.0; to: 0.0 }
|
||||
}
|
||||
|
||||
onOpened: {
|
||||
timer.start()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 500; running: false; repeat: false
|
||||
onTriggered: popupDialog.close()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user