Show busy if models.json download taking longer than expected.

This commit is contained in:
Adam Treat 2023-07-12 11:46:40 -04:00 committed by AT
parent 432b7ebbd7
commit e9897518d1
3 changed files with 39 additions and 2 deletions

View File

@ -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<QNetworkReply *>(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<QNetworkReply *>(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<QSslError> &errors)

View File

@ -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<QString> 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<QSslError> &errors);
private:
@ -328,6 +332,7 @@ private:
QList<ModelInfo*> m_models;
QHash<QString, ModelInfo*> m_modelMap;
QFileSystemWatcher *m_watcher;
bool m_asyncModelRequestOngoing;
private:
explicit ModelList();

View File

@ -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