gpt4all/gpt4all-chat/bravesearch.h
Adam Treat dfe3e951d4 Refactor the brave search and introduce an abstraction for tool calls.
Signed-off-by: Adam Treat <treat.adam@gmail.com>
2024-08-14 07:43:48 -04:00

49 lines
997 B
C++

#ifndef BRAVESEARCH_H
#define BRAVESEARCH_H
#include "sourceexcerpt.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)
, m_topK(1) {}
virtual ~BraveAPIWorker() {}
QString response() const { return m_response; }
public Q_SLOTS:
void request(const QString &apiKey, const QString &query, int topK);
Q_SIGNALS:
void finished();
private Q_SLOTS:
void handleFinished();
void handleErrorOccurred(QNetworkReply::NetworkError code);
private:
QNetworkAccessManager *m_networkManager;
QString m_response;
int m_topK;
};
class BraveSearch : public Tool {
Q_OBJECT
public:
BraveSearch() : Tool() {}
virtual ~BraveSearch() {}
QString run(const QJsonObject &parameters, qint64 timeout = 2000) override;
};
#endif // BRAVESEARCH_H