Wait just a bit to set the model name so that we can display the proper name instead of filename.

This commit is contained in:
Adam Treat 2023-06-26 20:59:46 -04:00
parent db34a2f670
commit c24ad02a6a
4 changed files with 36 additions and 10 deletions

View File

@ -352,6 +352,8 @@ void Download::parseModelsJsonFile(const QByteArray &jsonData)
settings.setValue("defaultModel", firstModel);
settings.sync();
}
ModelList::globalInstance()->updateModelHasNames();
}
void Download::handleReleaseJsonDownloadFinished()

View File

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

View File

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

View File

@ -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<QString> 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<QString, ModelInfo*> m_modelMap;
QString m_localModelsPath;
QFileSystemWatcher *m_watcher;
bool m_modelHasNames;
private:
explicit ModelList();