Gracefully handle when we have a previous chat where the model that it used has gone away.

pull/520/head
Adam Treat 1 year ago
parent 8b80345c98
commit 5f372bd881

@ -22,6 +22,7 @@ Chat::Chat(QObject *parent)
connect(m_llmodel, &ChatLLM::responseStarted, this, &Chat::responseStarted, Qt::QueuedConnection); connect(m_llmodel, &ChatLLM::responseStarted, this, &Chat::responseStarted, Qt::QueuedConnection);
connect(m_llmodel, &ChatLLM::responseStopped, this, &Chat::responseStopped, Qt::QueuedConnection); connect(m_llmodel, &ChatLLM::responseStopped, this, &Chat::responseStopped, Qt::QueuedConnection);
connect(m_llmodel, &ChatLLM::modelNameChanged, this, &Chat::handleModelNameChanged, Qt::QueuedConnection); connect(m_llmodel, &ChatLLM::modelNameChanged, this, &Chat::handleModelNameChanged, Qt::QueuedConnection);
connect(m_llmodel, &ChatLLM::modelLoadingError, this, &Chat::modelLoadingError, Qt::QueuedConnection);
connect(m_llmodel, &ChatLLM::recalcChanged, this, &Chat::handleRecalculating, Qt::QueuedConnection); connect(m_llmodel, &ChatLLM::recalcChanged, this, &Chat::handleRecalculating, Qt::QueuedConnection);
connect(m_llmodel, &ChatLLM::generatedNameChanged, this, &Chat::generatedNameChanged, Qt::QueuedConnection); connect(m_llmodel, &ChatLLM::generatedNameChanged, this, &Chat::generatedNameChanged, Qt::QueuedConnection);

@ -82,6 +82,7 @@ Q_SIGNALS:
void reloadModelRequested(const QString &modelName); void reloadModelRequested(const QString &modelName);
void generateNameRequested(); void generateNameRequested();
void modelListChanged(); void modelListChanged();
void modelLoadingError(const QString &error);
private Q_SLOTS: private Q_SLOTS:
void handleResponseChanged(); void handleResponseChanged();

@ -213,6 +213,7 @@ void ChatListModel::restoreChat(Chat *chat)
{ {
chat->setParent(this); chat->setParent(this);
connect(chat, &Chat::nameChanged, this, &ChatListModel::nameChanged); connect(chat, &Chat::nameChanged, this, &ChatListModel::nameChanged);
connect(chat, &Chat::modelLoadingError, this, &ChatListModel::handleModelLoadingError);
if (m_dummyChat) { if (m_dummyChat) {
beginResetModel(); beginResetModel();

@ -105,6 +105,8 @@ public:
this, &ChatListModel::newChatCountChanged); this, &ChatListModel::newChatCountChanged);
connect(m_newChat, &Chat::nameChanged, connect(m_newChat, &Chat::nameChanged,
this, &ChatListModel::nameChanged); this, &ChatListModel::nameChanged);
connect(m_newChat, &Chat::modelLoadingError,
this, &ChatListModel::handleModelLoadingError);
setCurrentChat(m_newChat); setCurrentChat(m_newChat);
} }
@ -204,6 +206,13 @@ private Q_SLOTS:
emit dataChanged(index, index, {NameRole}); emit dataChanged(index, index, {NameRole});
} }
void handleModelLoadingError(const QString &error)
{
Chat *chat = qobject_cast<Chat *>(sender());
qWarning() << "ERROR:" << qPrintable(error) << "id" << chat->id();
removeChat(chat);
}
void printChats() void printChats()
{ {
for (auto c : m_chats) { for (auto c : m_chats) {

@ -127,7 +127,8 @@ bool ChatLLM::loadModel(const QString &modelName)
else else
emit sendModelLoaded(); emit sendModelLoaded();
} else { } else {
qWarning() << "ERROR: Could not find model at" << filePath; const QString error = QString("Could not find model %1").arg(modelName);
emit modelLoadingError(error);
} }
if (m_llmodel) if (m_llmodel)

@ -58,6 +58,7 @@ public Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
void isModelLoadedChanged(); void isModelLoadedChanged();
void modelLoadingError(const QString &error);
void responseChanged(); void responseChanged();
void responseStarted(); void responseStarted();
void responseStopped(); void responseStopped();

Loading…
Cancel
Save