diff --git a/gpt4all-chat/chatgpt.cpp b/gpt4all-chat/chatgpt.cpp index 2b72604d..13e9cd5d 100644 --- a/gpt4all-chat/chatgpt.cpp +++ b/gpt4all-chat/chatgpt.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -160,6 +161,7 @@ void ChatGPTWorker::request(const QString &apiKey, request.setRawHeader("Authorization", authorization.toUtf8()); m_networkManager = new QNetworkAccessManager(this); QNetworkReply *reply = m_networkManager->post(request, array); + connect(qApp, &QCoreApplication::aboutToQuit, reply, &QNetworkReply::abort); connect(reply, &QNetworkReply::finished, this, &ChatGPTWorker::handleFinished); connect(reply, &QNetworkReply::readyRead, this, &ChatGPTWorker::handleReadyRead); connect(reply, &QNetworkReply::errorOccurred, this, &ChatGPTWorker::handleErrorOccurred); diff --git a/gpt4all-chat/chatllm.cpp b/gpt4all-chat/chatllm.cpp index 3a42021b..088083d5 100644 --- a/gpt4all-chat/chatllm.cpp +++ b/gpt4all-chat/chatllm.cpp @@ -427,6 +427,9 @@ bool ChatLLM::handleResponse(int32_t token, const std::string &response) bool ChatLLM::handleRecalculate(bool isRecalc) { +#if defined(DEBUG) + qDebug() << "recalculate" << m_llmThread.objectName() << isRecalc; +#endif if (m_isRecalc != isRecalc) { m_isRecalc = isRecalc; emit recalcChanged(); @@ -597,6 +600,9 @@ void ChatLLM::handleChatIdChanged(const QString &id) bool ChatLLM::handleNamePrompt(int32_t token) { +#if defined(DEBUG) + qDebug() << "name prompt" << m_llmThread.objectName() << token; +#endif Q_UNUSED(token); qt_noop(); return !m_stopGenerating; @@ -604,6 +610,9 @@ bool ChatLLM::handleNamePrompt(int32_t token) bool ChatLLM::handleNameResponse(int32_t token, const std::string &response) { +#if defined(DEBUG) + qDebug() << "name response" << m_llmThread.objectName() << token << response; +#endif Q_UNUSED(token); m_nameResponse.append(response); @@ -615,28 +624,40 @@ bool ChatLLM::handleNameResponse(int32_t token, const std::string &response) bool ChatLLM::handleNameRecalculate(bool isRecalc) { +#if defined(DEBUG) + qDebug() << "name recalc" << m_llmThread.objectName() << isRecalc; +#endif Q_UNUSED(isRecalc); Q_UNREACHABLE(); - return !m_stopGenerating; + return false; } bool ChatLLM::handleSystemPrompt(int32_t token) { +#if defined(DEBUG) + qDebug() << "system prompt" << m_llmThread.objectName() << token << m_stopGenerating; +#endif Q_UNUSED(token); return !m_stopGenerating; } bool ChatLLM::handleSystemResponse(int32_t token, const std::string &response) { +#if defined(DEBUG) + qDebug() << "system response" << m_llmThread.objectName() << token << response << m_stopGenerating; +#endif Q_UNUSED(token); Q_UNUSED(response); - return !m_stopGenerating; + return false; } bool ChatLLM::handleSystemRecalculate(bool isRecalc) { +#if defined(DEBUG) + qDebug() << "system recalc" << m_llmThread.objectName() << isRecalc; +#endif Q_UNUSED(isRecalc); - return !m_stopGenerating; + return false; } bool ChatLLM::serialize(QDataStream &stream, int version) diff --git a/gpt4all-chat/download.cpp b/gpt4all-chat/download.cpp index dbcaf646..f0c0d987 100644 --- a/gpt4all-chat/download.cpp +++ b/gpt4all-chat/download.cpp @@ -94,6 +94,7 @@ void Download::updateReleaseNotes() conf.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(conf); QNetworkReply *jsonReply = m_networkManager.get(request); + connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort); connect(jsonReply, &QNetworkReply::finished, this, &Download::handleReleaseJsonDownloadFinished); } @@ -137,6 +138,7 @@ void Download::downloadModel(const QString &modelFile) conf.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(conf); QNetworkReply *modelReply = m_networkManager.get(request); + connect(qApp, &QCoreApplication::aboutToQuit, modelReply, &QNetworkReply::abort); connect(modelReply, &QNetworkReply::downloadProgress, this, &Download::handleDownloadProgress); connect(modelReply, &QNetworkReply::finished, this, &Download::handleModelDownloadFinished); connect(modelReply, &QNetworkReply::readyRead, this, &Download::handleReadyRead); diff --git a/gpt4all-chat/modellist.cpp b/gpt4all-chat/modellist.cpp index 5a7deed6..e0bb12de 100644 --- a/gpt4all-chat/modellist.cpp +++ b/gpt4all-chat/modellist.cpp @@ -868,6 +868,7 @@ void ModelList::updateModelsFromJson() conf.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(conf); QNetworkReply *jsonReply = m_networkManager.get(request); + connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort); QEventLoop loop; connect(jsonReply, &QNetworkReply::finished, &loop, &QEventLoop::quit); QTimer::singleShot(1500, &loop, &QEventLoop::quit); @@ -908,6 +909,7 @@ void ModelList::updateModelsFromJsonAsync() conf.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(conf); QNetworkReply *jsonReply = m_networkManager.get(request); + connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort); connect(jsonReply, &QNetworkReply::finished, this, &ModelList::handleModelsJsonDownloadFinished); } diff --git a/gpt4all-chat/network.cpp b/gpt4all-chat/network.cpp index 61ebfa61..7317e7fe 100644 --- a/gpt4all-chat/network.cpp +++ b/gpt4all-chat/network.cpp @@ -115,6 +115,7 @@ bool Network::packageAndSendJson(const QString &ingestId, const QString &json) QByteArray body(newDoc.toJson(QJsonDocument::Compact)); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QNetworkReply *jsonReply = m_networkManager.post(request, body); + connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort); connect(jsonReply, &QNetworkReply::finished, this, &Network::handleJsonUploadFinished); m_activeUploads.append(jsonReply); return true; @@ -434,6 +435,7 @@ void Network::sendIpify() conf.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(conf); QNetworkReply *reply = m_networkManager.get(request); + connect(qApp, &QCoreApplication::aboutToQuit, reply, &QNetworkReply::abort); connect(reply, &QNetworkReply::finished, this, &Network::handleIpifyFinished); } @@ -449,6 +451,7 @@ void Network::sendMixpanel(const QByteArray &json, bool isOptOut) request.setSslConfiguration(conf); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QNetworkReply *trackReply = m_networkManager.post(request, json); + connect(qApp, &QCoreApplication::aboutToQuit, trackReply, &QNetworkReply::abort); connect(trackReply, &QNetworkReply::finished, this, &Network::handleMixpanelFinished); } @@ -512,6 +515,7 @@ void Network::sendHealth() conf.setPeerVerifyMode(QSslSocket::VerifyNone); request.setSslConfiguration(conf); QNetworkReply *healthReply = m_networkManager.get(request); + connect(qApp, &QCoreApplication::aboutToQuit, healthReply, &QNetworkReply::abort); connect(healthReply, &QNetworkReply::finished, this, &Network::handleHealthFinished); }