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::responseStopped, this, &Chat::responseStopped, 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::generatedNameChanged, this, &Chat::generatedNameChanged, Qt::QueuedConnection);

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

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

@ -105,6 +105,8 @@ public:
this, &ChatListModel::newChatCountChanged);
connect(m_newChat, &Chat::nameChanged,
this, &ChatListModel::nameChanged);
connect(m_newChat, &Chat::modelLoadingError,
this, &ChatListModel::handleModelLoadingError);
setCurrentChat(m_newChat);
}
@ -204,6 +206,13 @@ private Q_SLOTS:
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()
{
for (auto c : m_chats) {

@ -127,7 +127,8 @@ bool ChatLLM::loadModel(const QString &modelName)
else
emit sendModelLoaded();
} 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)

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

Loading…
Cancel
Save