Cleanup the chatllm properly.

This commit is contained in:
Adam Treat 2023-05-12 14:06:03 -04:00 committed by AT
parent 57ba554478
commit 76675536b0
4 changed files with 21 additions and 0 deletions

View File

@ -11,6 +11,17 @@ Chat::Chat(QObject *parent)
, m_responseInProgress(false)
, m_creationDate(QDateTime::currentSecsSinceEpoch())
, m_llmodel(new ChatLLM(this))
{
connectLLM();
}
Chat::~Chat()
{
delete m_llmodel;
m_llmodel = nullptr;
}
void Chat::connectLLM()
{
// Should be in same thread
connect(Download::globalInstance(), &Download::modelListChanged, this, &Chat::modelListChanged, Qt::DirectConnection);

View File

@ -25,6 +25,8 @@ class Chat : public QObject
public:
explicit Chat(QObject *parent = nullptr);
virtual ~Chat();
void connectLLM();
QString id() const { return m_id; }
QString name() const { return m_userName.isEmpty() ? m_name : m_userName; }

View File

@ -53,6 +53,13 @@ ChatLLM::ChatLLM(Chat *parent)
m_llmThread.start();
}
ChatLLM::~ChatLLM()
{
m_llmThread.quit();
m_llmThread.wait();
delete m_llmodel;
}
bool ChatLLM::loadDefaultModel()
{
const QList<QString> models = m_chat->modelList();

View File

@ -24,6 +24,7 @@ public:
};
ChatLLM(Chat *parent);
virtual ~ChatLLM();
bool isModelLoaded() const;
void regenerateResponse();