Get rid of blocking behavior for regenerate response.

This commit is contained in:
Adam Treat 2023-05-30 18:17:59 -04:00
parent 0e82d87032
commit 26afbde1ae
4 changed files with 4 additions and 12 deletions

View File

@ -63,10 +63,10 @@ void Chat::connectLLM()
connect(this, &Chat::loadDefaultModelRequested, m_llmodel, &ChatLLM::loadDefaultModel, Qt::QueuedConnection); connect(this, &Chat::loadDefaultModelRequested, m_llmodel, &ChatLLM::loadDefaultModel, Qt::QueuedConnection);
connect(this, &Chat::loadModelRequested, m_llmodel, &ChatLLM::loadModel, Qt::QueuedConnection); connect(this, &Chat::loadModelRequested, m_llmodel, &ChatLLM::loadModel, Qt::QueuedConnection);
connect(this, &Chat::generateNameRequested, m_llmodel, &ChatLLM::generateName, Qt::QueuedConnection); connect(this, &Chat::generateNameRequested, m_llmodel, &ChatLLM::generateName, Qt::QueuedConnection);
connect(this, &Chat::regenerateResponseRequested, m_llmodel, &ChatLLM::regenerateResponse, Qt::QueuedConnection);
// The following are blocking operations and will block the gui thread, therefore must be fast // The following are blocking operations and will block the gui thread, therefore must be fast
// to respond to // to respond to
connect(this, &Chat::regenerateResponseRequested, m_llmodel, &ChatLLM::regenerateResponse, Qt::BlockingQueuedConnection);
connect(this, &Chat::resetResponseRequested, m_llmodel, &ChatLLM::resetResponse, Qt::BlockingQueuedConnection); connect(this, &Chat::resetResponseRequested, m_llmodel, &ChatLLM::resetResponse, Qt::BlockingQueuedConnection);
connect(this, &Chat::resetContextRequested, m_llmodel, &ChatLLM::resetContext, Qt::BlockingQueuedConnection); connect(this, &Chat::resetContextRequested, m_llmodel, &ChatLLM::resetContext, Qt::BlockingQueuedConnection);
} }
@ -151,7 +151,7 @@ void Chat::handleLocalDocsRetrieved(const QString &uid, const QList<ResultInfo>
void Chat::regenerateResponse() void Chat::regenerateResponse()
{ {
emit regenerateResponseRequested(); // blocking queued connection emit regenerateResponseRequested();
} }
void Chat::stopGenerating() void Chat::stopGenerating()

View File

@ -146,7 +146,7 @@ bool ChatLLM::loadModel(const QString &modelName)
// We have a live model, but it isn't the one we want // We have a live model, but it isn't the one we want
bool alreadyAcquired = isModelLoaded(); bool alreadyAcquired = isModelLoaded();
if (alreadyAcquired) { if (alreadyAcquired) {
resetContextProtected(); resetContext();
#if defined(DEBUG_MODEL_LOADING) #if defined(DEBUG_MODEL_LOADING)
qDebug() << "already acquired model deleted" << m_chat->id() << m_modelInfo.model; qDebug() << "already acquired model deleted" << m_chat->id() << m_modelInfo.model;
#endif #endif
@ -301,12 +301,6 @@ void ChatLLM::resetResponse()
} }
void ChatLLM::resetContext() void ChatLLM::resetContext()
{
resetContextProtected();
emit sendResetContext();
}
void ChatLLM::resetContextProtected()
{ {
regenerateResponse(); regenerateResponse();
m_ctx = LLModel::PromptContext(); m_ctx = LLModel::PromptContext();

View File

@ -81,14 +81,12 @@ Q_SIGNALS:
void recalcChanged(); void recalcChanged();
void sendStartup(); void sendStartup();
void sendModelLoaded(); void sendModelLoaded();
void sendResetContext();
void generatedNameChanged(); void generatedNameChanged();
void stateChanged(); void stateChanged();
void threadStarted(); void threadStarted();
void shouldBeLoadedChanged(); void shouldBeLoadedChanged();
protected: protected:
void resetContextProtected();
bool handlePrompt(int32_t token); bool handlePrompt(int32_t token);
bool handleResponse(int32_t token, const std::string &response); bool handleResponse(int32_t token, const std::string &response);
bool handleRecalculate(bool isRecalc); bool handleRecalculate(bool isRecalc);

View File

@ -286,7 +286,7 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
} }
// don't remember any context // don't remember any context
resetContextProtected(); resetContext();
QSettings settings; QSettings settings;
settings.sync(); settings.sync();