From e9897518d1c132f0f75d3ebc1a6d7a4b53b0bbee Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Wed, 12 Jul 2023 11:46:40 -0400 Subject: [PATCH] Show busy if models.json download taking longer than expected. --- gpt4all-chat/modellist.cpp | 26 +++++++++++++++++++++- gpt4all-chat/modellist.h | 5 +++++ gpt4all-chat/qml/ModelDownloaderDialog.qml | 10 ++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gpt4all-chat/modellist.cpp b/gpt4all-chat/modellist.cpp index 1a622c07..425c1c85 100644 --- a/gpt4all-chat/modellist.cpp +++ b/gpt4all-chat/modellist.cpp @@ -222,6 +222,7 @@ ModelList::ModelList() : QAbstractListModel(nullptr) , m_installedModels(new InstalledModels(this)) , m_downloadableModels(new DownloadableModels(this)) + , m_asyncModelRequestOngoing(false) { m_installedModels->setSourceModel(this); m_downloadableModels->setSourceModel(this); @@ -899,6 +900,9 @@ void ModelList::updateModelsFromJson() void ModelList::updateModelsFromJsonAsync() { + m_asyncModelRequestOngoing = true; + emit asyncModelRequestOngoingChanged(); + #if defined(USE_LOCAL_MODELSJSON) QUrl jsonUrl("file://" + QDir::homePath() + "/dev/large_language_models/gpt4all/gpt4all-chat/metadata/models.json"); #else @@ -911,17 +915,37 @@ void ModelList::updateModelsFromJsonAsync() QNetworkReply *jsonReply = m_networkManager.get(request); connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort); connect(jsonReply, &QNetworkReply::finished, this, &ModelList::handleModelsJsonDownloadFinished); + connect(jsonReply, &QNetworkReply::errorOccurred, this, &ModelList::handleModelsJsonDownloadErrorOccurred); } void ModelList::handleModelsJsonDownloadFinished() { QNetworkReply *jsonReply = qobject_cast(sender()); - if (!jsonReply) + if (!jsonReply) { + m_asyncModelRequestOngoing = false; + emit asyncModelRequestOngoingChanged(); return; + } QByteArray jsonData = jsonReply->readAll(); jsonReply->deleteLater(); parseModelsJsonFile(jsonData, true); + m_asyncModelRequestOngoing = false; + emit asyncModelRequestOngoingChanged(); +} + +void ModelList::handleModelsJsonDownloadErrorOccurred(QNetworkReply::NetworkError code) +{ + // TODO: Show what error occured in the GUI + m_asyncModelRequestOngoing = false; + emit asyncModelRequestOngoingChanged(); + + QNetworkReply *reply = qobject_cast(sender()); + if (!reply) + return; + + qWarning() << QString("ERROR: Modellist download failed with error code \"%1-%2\"") + .arg(code).arg(reply->errorString()).toStdString(); } void ModelList::handleSslErrors(QNetworkReply *reply, const QList &errors) diff --git a/gpt4all-chat/modellist.h b/gpt4all-chat/modellist.h index c749254c..b2d40332 100644 --- a/gpt4all-chat/modellist.h +++ b/gpt4all-chat/modellist.h @@ -169,6 +169,7 @@ class ModelList : public QAbstractListModel Q_PROPERTY(InstalledModels* installedModels READ installedModels NOTIFY installedModelsChanged) Q_PROPERTY(DownloadableModels* downloadableModels READ downloadableModels NOTIFY downloadableModelsChanged) Q_PROPERTY(QList userDefaultModelList READ userDefaultModelList NOTIFY userDefaultModelListChanged) + Q_PROPERTY(bool asyncModelRequestOngoing READ asyncModelRequestOngoing NOTIFY asyncModelRequestOngoingChanged) public: static ModelList *globalInstance(); @@ -296,12 +297,14 @@ public: } QString incompleteDownloadPath(const QString &modelFile); + bool asyncModelRequestOngoing() const { return m_asyncModelRequestOngoing; } Q_SIGNALS: void countChanged(); void installedModelsChanged(); void downloadableModelsChanged(); void userDefaultModelListChanged(); + void asyncModelRequestOngoingChanged(); private Q_SLOTS: void updateModelsFromJson(); @@ -310,6 +313,7 @@ private Q_SLOTS: void updateModelsFromDirectory(); void updateDataForSettings(); void handleModelsJsonDownloadFinished(); + void handleModelsJsonDownloadErrorOccurred(QNetworkReply::NetworkError code); void handleSslErrors(QNetworkReply *reply, const QList &errors); private: @@ -328,6 +332,7 @@ private: QList m_models; QHash m_modelMap; QFileSystemWatcher *m_watcher; + bool m_asyncModelRequestOngoing; private: explicit ModelList(); diff --git a/gpt4all-chat/qml/ModelDownloaderDialog.qml b/gpt4all-chat/qml/ModelDownloaderDialog.qml index 000e05f2..4decb63f 100644 --- a/gpt4all-chat/qml/ModelDownloaderDialog.qml +++ b/gpt4all-chat/qml/ModelDownloaderDialog.qml @@ -41,7 +41,7 @@ MyDialog { } Label { - visible: !ModelList.downloadableModels.count + visible: !ModelList.downloadableModels.count && !ModelList.asyncModelRequestOngoing Layout.fillWidth: true Layout.fillHeight: true horizontalAlignment: Qt.AlignHCenter @@ -50,6 +50,14 @@ MyDialog { color: theme.mutedTextColor } + MyBusyIndicator { + visible: !ModelList.downloadableModels.count && ModelList.asyncModelRequestOngoing + running: ModelList.asyncModelRequestOngoing + Accessible.role: Accessible.Animation + Accessible.name: qsTr("Busy indicator") + Accessible.description: qsTr("Displayed when the models request is ongoing") + } + ScrollView { id: scrollView ScrollBar.vertical.policy: ScrollBar.AlwaysOn