mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2024-10-01 01:06:10 -04:00
244b82622c
Signed-off-by: Adam Treat <treat.adam@gmail.com>
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#ifndef BRAVESEARCH_H
|
|
#define BRAVESEARCH_H
|
|
|
|
#include "tool.h"
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkReply>
|
|
|
|
class BraveAPIWorker : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
BraveAPIWorker()
|
|
: QObject(nullptr)
|
|
, m_networkManager(nullptr) {}
|
|
virtual ~BraveAPIWorker() {}
|
|
|
|
QString response() const { return m_response; }
|
|
ToolEnums::Error error() const { return m_error; }
|
|
QString errorString() const { return m_errorString; }
|
|
|
|
public Q_SLOTS:
|
|
void request(const QString &apiKey, const QString &query, int count);
|
|
|
|
Q_SIGNALS:
|
|
void finished();
|
|
|
|
private Q_SLOTS:
|
|
QString cleanBraveResponse(const QByteArray& jsonResponse);
|
|
void handleFinished();
|
|
void handleErrorOccurred(QNetworkReply::NetworkError code);
|
|
|
|
private:
|
|
QNetworkAccessManager *m_networkManager;
|
|
QString m_response;
|
|
ToolEnums::Error m_error;
|
|
QString m_errorString;
|
|
};
|
|
|
|
class BraveSearch : public Tool {
|
|
Q_OBJECT
|
|
public:
|
|
BraveSearch() : Tool(), m_error(ToolEnums::Error::NoError) {}
|
|
virtual ~BraveSearch() {}
|
|
|
|
QString run(const QJsonObject ¶meters, qint64 timeout = 2000) override;
|
|
ToolEnums::Error error() const override { return m_error; }
|
|
QString errorString() const override { return m_errorString; }
|
|
|
|
private:
|
|
ToolEnums::Error m_error;
|
|
QString m_errorString;
|
|
};
|
|
|
|
#endif // BRAVESEARCH_H
|