gpt4all/network.h

88 lines
2.6 KiB
C
Raw Normal View History

#ifndef NETWORK_H
#define NETWORK_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonValue>
struct KeyValue {
QString key;
QJsonValue value;
};
class Network : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isActive READ isActive WRITE setActive NOTIFY activeChanged)
2023-04-28 10:54:05 -04:00
Q_PROPERTY(bool usageStatsActive READ usageStatsActive WRITE setUsageStatsActive NOTIFY usageStatsActiveChanged)
public:
static Network *globalInstance();
bool isActive() const { return m_isActive; }
void setActive(bool b);
2023-04-28 10:54:05 -04:00
bool usageStatsActive() const { return m_usageStatsActive; }
void setUsageStatsActive(bool b);
Q_INVOKABLE QString generateUniqueId() const;
2023-04-23 21:05:38 -04:00
Q_INVOKABLE bool sendConversation(const QString &ingestId, const QString &conversation);
Q_SIGNALS:
void activeChanged();
2023-04-28 10:54:05 -04:00
void usageStatsActiveChanged();
void healthCheckFailed(int code);
2023-04-26 22:05:56 -04:00
public Q_SLOTS:
2023-04-28 10:54:05 -04:00
void sendOptOut();
2023-04-26 22:05:56 -04:00
void sendModelLoaded();
void sendStartup();
2023-04-27 07:41:23 -04:00
void sendCheckForUpdates();
Q_INVOKABLE void sendModelDownloaderDialog();
Q_INVOKABLE void sendResetContext(int conversationLength);
void sendDownloadStarted(const QString &model);
void sendDownloadCanceled(const QString &model);
void sendDownloadError(const QString &model, int code, const QString &errorString);
void sendDownloadFinished(const QString &model, bool success);
Q_INVOKABLE void sendSettingsDialog();
Q_INVOKABLE void sendNetworkToggled(bool active);
Q_INVOKABLE void sendSaveChatsToggled(bool active);
Q_INVOKABLE void sendNewChat(int count);
Q_INVOKABLE void sendRemoveChat();
Q_INVOKABLE void sendRenameChat();
Q_INVOKABLE void sendNonCompatHardware();
void sendChatStarted();
void sendRecalculatingContext(int conversationLength);
2023-04-26 22:05:56 -04:00
private Q_SLOTS:
2023-04-26 22:05:56 -04:00
void handleIpifyFinished();
void handleHealthFinished();
void handleJsonUploadFinished();
2023-04-24 17:52:19 -04:00
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
2023-04-26 22:05:56 -04:00
void handleMixpanelFinished();
private:
void sendHealth();
2023-04-26 22:05:56 -04:00
void sendIpify();
void sendMixpanelEvent(const QString &event, const QVector<KeyValue> &values = QVector<KeyValue>());
2023-04-29 11:05:44 -04:00
void sendMixpanel(const QByteArray &json, bool isOptOut = false);
2023-04-23 21:05:38 -04:00
bool packageAndSendJson(const QString &ingestId, const QString &json);
private:
2023-04-26 22:05:56 -04:00
bool m_shouldSendStartup;
bool m_isActive;
2023-04-28 10:54:05 -04:00
bool m_usageStatsActive;
2023-04-26 22:05:56 -04:00
QString m_ipify;
QString m_uniqueId;
QNetworkAccessManager m_networkManager;
QVector<QNetworkReply*> m_activeUploads;
private:
explicit Network();
~Network() {}
friend class MyNetwork;
};
#endif // LLM_H