mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-18 03:25:46 +00:00
Don't block on exit when not connected.
This commit is contained in:
parent
88bbe30952
commit
34a3b9c857
@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -160,6 +161,7 @@ void ChatGPTWorker::request(const QString &apiKey,
|
|||||||
request.setRawHeader("Authorization", authorization.toUtf8());
|
request.setRawHeader("Authorization", authorization.toUtf8());
|
||||||
m_networkManager = new QNetworkAccessManager(this);
|
m_networkManager = new QNetworkAccessManager(this);
|
||||||
QNetworkReply *reply = m_networkManager->post(request, array);
|
QNetworkReply *reply = m_networkManager->post(request, array);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, reply, &QNetworkReply::abort);
|
||||||
connect(reply, &QNetworkReply::finished, this, &ChatGPTWorker::handleFinished);
|
connect(reply, &QNetworkReply::finished, this, &ChatGPTWorker::handleFinished);
|
||||||
connect(reply, &QNetworkReply::readyRead, this, &ChatGPTWorker::handleReadyRead);
|
connect(reply, &QNetworkReply::readyRead, this, &ChatGPTWorker::handleReadyRead);
|
||||||
connect(reply, &QNetworkReply::errorOccurred, this, &ChatGPTWorker::handleErrorOccurred);
|
connect(reply, &QNetworkReply::errorOccurred, this, &ChatGPTWorker::handleErrorOccurred);
|
||||||
|
@ -427,6 +427,9 @@ bool ChatLLM::handleResponse(int32_t token, const std::string &response)
|
|||||||
|
|
||||||
bool ChatLLM::handleRecalculate(bool isRecalc)
|
bool ChatLLM::handleRecalculate(bool isRecalc)
|
||||||
{
|
{
|
||||||
|
#if defined(DEBUG)
|
||||||
|
qDebug() << "recalculate" << m_llmThread.objectName() << isRecalc;
|
||||||
|
#endif
|
||||||
if (m_isRecalc != isRecalc) {
|
if (m_isRecalc != isRecalc) {
|
||||||
m_isRecalc = isRecalc;
|
m_isRecalc = isRecalc;
|
||||||
emit recalcChanged();
|
emit recalcChanged();
|
||||||
@ -597,6 +600,9 @@ void ChatLLM::handleChatIdChanged(const QString &id)
|
|||||||
|
|
||||||
bool ChatLLM::handleNamePrompt(int32_t token)
|
bool ChatLLM::handleNamePrompt(int32_t token)
|
||||||
{
|
{
|
||||||
|
#if defined(DEBUG)
|
||||||
|
qDebug() << "name prompt" << m_llmThread.objectName() << token;
|
||||||
|
#endif
|
||||||
Q_UNUSED(token);
|
Q_UNUSED(token);
|
||||||
qt_noop();
|
qt_noop();
|
||||||
return !m_stopGenerating;
|
return !m_stopGenerating;
|
||||||
@ -604,6 +610,9 @@ bool ChatLLM::handleNamePrompt(int32_t token)
|
|||||||
|
|
||||||
bool ChatLLM::handleNameResponse(int32_t token, const std::string &response)
|
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);
|
Q_UNUSED(token);
|
||||||
|
|
||||||
m_nameResponse.append(response);
|
m_nameResponse.append(response);
|
||||||
@ -615,28 +624,40 @@ bool ChatLLM::handleNameResponse(int32_t token, const std::string &response)
|
|||||||
|
|
||||||
bool ChatLLM::handleNameRecalculate(bool isRecalc)
|
bool ChatLLM::handleNameRecalculate(bool isRecalc)
|
||||||
{
|
{
|
||||||
|
#if defined(DEBUG)
|
||||||
|
qDebug() << "name recalc" << m_llmThread.objectName() << isRecalc;
|
||||||
|
#endif
|
||||||
Q_UNUSED(isRecalc);
|
Q_UNUSED(isRecalc);
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
return !m_stopGenerating;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLLM::handleSystemPrompt(int32_t token)
|
bool ChatLLM::handleSystemPrompt(int32_t token)
|
||||||
{
|
{
|
||||||
|
#if defined(DEBUG)
|
||||||
|
qDebug() << "system prompt" << m_llmThread.objectName() << token << m_stopGenerating;
|
||||||
|
#endif
|
||||||
Q_UNUSED(token);
|
Q_UNUSED(token);
|
||||||
return !m_stopGenerating;
|
return !m_stopGenerating;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLLM::handleSystemResponse(int32_t token, const std::string &response)
|
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(token);
|
||||||
Q_UNUSED(response);
|
Q_UNUSED(response);
|
||||||
return !m_stopGenerating;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLLM::handleSystemRecalculate(bool isRecalc)
|
bool ChatLLM::handleSystemRecalculate(bool isRecalc)
|
||||||
{
|
{
|
||||||
|
#if defined(DEBUG)
|
||||||
|
qDebug() << "system recalc" << m_llmThread.objectName() << isRecalc;
|
||||||
|
#endif
|
||||||
Q_UNUSED(isRecalc);
|
Q_UNUSED(isRecalc);
|
||||||
return !m_stopGenerating;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLLM::serialize(QDataStream &stream, int version)
|
bool ChatLLM::serialize(QDataStream &stream, int version)
|
||||||
|
@ -94,6 +94,7 @@ void Download::updateReleaseNotes()
|
|||||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
QNetworkReply *jsonReply = m_networkManager.get(request);
|
QNetworkReply *jsonReply = m_networkManager.get(request);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort);
|
||||||
connect(jsonReply, &QNetworkReply::finished, this, &Download::handleReleaseJsonDownloadFinished);
|
connect(jsonReply, &QNetworkReply::finished, this, &Download::handleReleaseJsonDownloadFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +138,7 @@ void Download::downloadModel(const QString &modelFile)
|
|||||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
QNetworkReply *modelReply = m_networkManager.get(request);
|
QNetworkReply *modelReply = m_networkManager.get(request);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, modelReply, &QNetworkReply::abort);
|
||||||
connect(modelReply, &QNetworkReply::downloadProgress, this, &Download::handleDownloadProgress);
|
connect(modelReply, &QNetworkReply::downloadProgress, this, &Download::handleDownloadProgress);
|
||||||
connect(modelReply, &QNetworkReply::finished, this, &Download::handleModelDownloadFinished);
|
connect(modelReply, &QNetworkReply::finished, this, &Download::handleModelDownloadFinished);
|
||||||
connect(modelReply, &QNetworkReply::readyRead, this, &Download::handleReadyRead);
|
connect(modelReply, &QNetworkReply::readyRead, this, &Download::handleReadyRead);
|
||||||
|
@ -868,6 +868,7 @@ void ModelList::updateModelsFromJson()
|
|||||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
QNetworkReply *jsonReply = m_networkManager.get(request);
|
QNetworkReply *jsonReply = m_networkManager.get(request);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort);
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(jsonReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
connect(jsonReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
QTimer::singleShot(1500, &loop, &QEventLoop::quit);
|
QTimer::singleShot(1500, &loop, &QEventLoop::quit);
|
||||||
@ -908,6 +909,7 @@ void ModelList::updateModelsFromJsonAsync()
|
|||||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
QNetworkReply *jsonReply = m_networkManager.get(request);
|
QNetworkReply *jsonReply = m_networkManager.get(request);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort);
|
||||||
connect(jsonReply, &QNetworkReply::finished, this, &ModelList::handleModelsJsonDownloadFinished);
|
connect(jsonReply, &QNetworkReply::finished, this, &ModelList::handleModelsJsonDownloadFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ bool Network::packageAndSendJson(const QString &ingestId, const QString &json)
|
|||||||
QByteArray body(newDoc.toJson(QJsonDocument::Compact));
|
QByteArray body(newDoc.toJson(QJsonDocument::Compact));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *jsonReply = m_networkManager.post(request, body);
|
QNetworkReply *jsonReply = m_networkManager.post(request, body);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, jsonReply, &QNetworkReply::abort);
|
||||||
connect(jsonReply, &QNetworkReply::finished, this, &Network::handleJsonUploadFinished);
|
connect(jsonReply, &QNetworkReply::finished, this, &Network::handleJsonUploadFinished);
|
||||||
m_activeUploads.append(jsonReply);
|
m_activeUploads.append(jsonReply);
|
||||||
return true;
|
return true;
|
||||||
@ -434,6 +435,7 @@ void Network::sendIpify()
|
|||||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
QNetworkReply *reply = m_networkManager.get(request);
|
QNetworkReply *reply = m_networkManager.get(request);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, reply, &QNetworkReply::abort);
|
||||||
connect(reply, &QNetworkReply::finished, this, &Network::handleIpifyFinished);
|
connect(reply, &QNetworkReply::finished, this, &Network::handleIpifyFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,6 +451,7 @@ void Network::sendMixpanel(const QByteArray &json, bool isOptOut)
|
|||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *trackReply = m_networkManager.post(request, json);
|
QNetworkReply *trackReply = m_networkManager.post(request, json);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, trackReply, &QNetworkReply::abort);
|
||||||
connect(trackReply, &QNetworkReply::finished, this, &Network::handleMixpanelFinished);
|
connect(trackReply, &QNetworkReply::finished, this, &Network::handleMixpanelFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,6 +515,7 @@ void Network::sendHealth()
|
|||||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
request.setSslConfiguration(conf);
|
request.setSslConfiguration(conf);
|
||||||
QNetworkReply *healthReply = m_networkManager.get(request);
|
QNetworkReply *healthReply = m_networkManager.get(request);
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, healthReply, &QNetworkReply::abort);
|
||||||
connect(healthReply, &QNetworkReply::finished, this, &Network::handleHealthFinished);
|
connect(healthReply, &QNetworkReply::finished, this, &Network::handleHealthFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user