From c24ad02a6a91d37b876695b1ff12678b390abcf4 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Mon, 26 Jun 2023 20:59:46 -0400 Subject: [PATCH] Wait just a bit to set the model name so that we can display the proper name instead of filename. --- gpt4all-chat/download.cpp | 2 ++ gpt4all-chat/main.qml | 37 +++++++++++++++++++++++++++---------- gpt4all-chat/modellist.cpp | 1 + gpt4all-chat/modellist.h | 6 ++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/gpt4all-chat/download.cpp b/gpt4all-chat/download.cpp index 3d08475d..9a68d495 100644 --- a/gpt4all-chat/download.cpp +++ b/gpt4all-chat/download.cpp @@ -352,6 +352,8 @@ void Download::parseModelsJsonFile(const QByteArray &jsonData) settings.setValue("defaultModel", firstModel); settings.sync(); } + + ModelList::globalInstance()->updateModelHasNames(); } void Download::handleReleaseJsonDownloadFinished() diff --git a/gpt4all-chat/main.qml b/gpt4all-chat/main.qml index 3f35258a..4549ca17 100644 --- a/gpt4all-chat/main.qml +++ b/gpt4all-chat/main.qml @@ -205,23 +205,40 @@ Window { model: ModelList.installedModels valueRole: "filename" textRole: "name" + property string currentModelName: "" + Timer { + id: startupTimer + interval: 3000 // 3 seconds + running: true + repeat: false + } + function updateCurrentModelName() { + // During application startup the model names might not be processed yet, so don't + // set the combobox text until this is done OR the timer has timed out + if (!ModelList.modelHasNames && startupTimer.running) + return + var info = ModelList.modelInfo(currentChat.modelInfo.filename); + comboBox.currentModelName = info.name !== "" ? info.name : info.filename; + } + Connections { + target: ModelList + function onModelHasNamesChanged() { + comboBox.updateCurrentModelName(); + } + } Connections { target: currentChat function onModelInfoChanged() { - comboBox.currentIndex = comboBox.indexOfValue(currentChat.modelInfo.filename) + comboBox.updateCurrentModelName(); } } contentItem: Text { anchors.horizontalCenter: parent.horizontalCenter leftPadding: 10 rightPadding: 20 - text: (ModelList.installedModels.count > 0 - ? currentChat.modelLoadingError !== "" ? qsTr("Model loading error...") - : (comboBox.textAt(comboBox.currentIndex) !== "" - ? comboBox.textAt(comboBox.currentIndex) - : (comboBox.valueAt(comboBox.currentIndex) !== "undefined" ? "" - : comboBox.valueAt(comboBox.currentIndex))) - : "") + text: currentChat.modelLoadingError !== "" + ? qsTr("Model loading error...") + : comboBox.currentModelName font: comboBox.font color: theme.textColor verticalAlignment: Text.AlignVCenter @@ -245,10 +262,10 @@ Window { Accessible.role: Accessible.ComboBox Accessible.name: qsTr("ComboBox for displaying/picking the current model") Accessible.description: qsTr("Use this for picking the current model to use; the first item is the current model") - onActivated: { + onActivated: function (index) { currentChat.stopGenerating() currentChat.reset(); - currentChat.modelInfo = ModelList.modelInfo(comboBox.valueAt(comboBox.currentIndex)) + currentChat.modelInfo = ModelList.modelInfo(comboBox.valueAt(index)) } } } diff --git a/gpt4all-chat/modellist.cpp b/gpt4all-chat/modellist.cpp index 5fe8735b..e98ac0b0 100644 --- a/gpt4all-chat/modellist.cpp +++ b/gpt4all-chat/modellist.cpp @@ -85,6 +85,7 @@ ModelList::ModelList() : QAbstractListModel(nullptr) , m_installedModels(new InstalledModels(this)) , m_downloadableModels(new DownloadableModels(this)) + , m_modelHasNames(false) { m_installedModels->setSourceModel(this); m_downloadableModels->setSourceModel(this); diff --git a/gpt4all-chat/modellist.h b/gpt4all-chat/modellist.h index ea8fb82b..b7d75160 100644 --- a/gpt4all-chat/modellist.h +++ b/gpt4all-chat/modellist.h @@ -116,6 +116,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 modelHasNames READ modelHasNames NOTIFY modelHasNamesChanged) public: static ModelList *globalInstance(); @@ -218,12 +219,16 @@ public: QString incompleteDownloadPath(const QString &modelFile); + bool modelHasNames() const { return m_modelHasNames; } + void updateModelHasNames() { m_modelHasNames = true; emit modelHasNamesChanged(); } + Q_SIGNALS: void countChanged(); void localModelsPathChanged(); void installedModelsChanged(); void downloadableModelsChanged(); void userDefaultModelListChanged(); + void modelHasNamesChanged(); private Q_SLOTS: void updateModelsFromDirectory(); @@ -242,6 +247,7 @@ private: QHash m_modelMap; QString m_localModelsPath; QFileSystemWatcher *m_watcher; + bool m_modelHasNames; private: explicit ModelList();