general ui work
This commit is contained in:
27
backend.h
27
backend.h
@ -7,6 +7,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <QUrl>
|
||||
#include <memory>
|
||||
|
||||
class AiBackend: public QObject
|
||||
{
|
||||
@ -21,17 +22,28 @@ public:
|
||||
|
||||
class Request
|
||||
{
|
||||
public:
|
||||
|
||||
typedef enum {
|
||||
INFERENCE,
|
||||
COUNT_TOKENS,
|
||||
LEFT_TRIM,
|
||||
UNKOWN
|
||||
} type_t;
|
||||
|
||||
protected:
|
||||
inline static uint32_t idCounter = 0;
|
||||
QString text;
|
||||
uint32_t id;
|
||||
void* userPtr;
|
||||
type_t type;
|
||||
|
||||
public:
|
||||
Request() = default;
|
||||
Request(const QString& text, void* userPtr = nullptr);
|
||||
Request(const QString& text, type_t type = UNKOWN, void* userPtr = nullptr);
|
||||
const QString& getText() const;
|
||||
uint32_t getId() const;
|
||||
type_t getType() const;
|
||||
bool operator==(const Request& in);
|
||||
void* getUserPtr() const;
|
||||
};
|
||||
@ -40,11 +52,14 @@ public:
|
||||
{
|
||||
private:
|
||||
bool finished;
|
||||
int64_t tokens = -1;
|
||||
|
||||
public:
|
||||
Response() = default;
|
||||
Response(QString text, uint32_t id, bool finished, void* userPtr = nullptr);
|
||||
Response(QString text, uint32_t id, bool finished, type_t type = UNKOWN, int64_t tokens= -1, void* userPtr = nullptr);
|
||||
bool isFinished() const;
|
||||
int64_t getTokens() const;
|
||||
|
||||
void setUserPtr(void* ptr);
|
||||
};
|
||||
|
||||
@ -53,12 +68,15 @@ protected:
|
||||
|
||||
void feedResponse(Response response);
|
||||
bool isValidId(uint32_t id);
|
||||
virtual void generateImpl(const Request& request) = 0;
|
||||
virtual bool generateImpl(const Request& request) = 0;
|
||||
|
||||
public:
|
||||
|
||||
static std::vector<QString> getAvailableBackendNames();
|
||||
static std::shared_ptr<AiBackend> createBackend(const QString& name);
|
||||
virtual QString backendName() = 0;
|
||||
virtual bool ready() = 0;
|
||||
void generate(const Request& request);
|
||||
bool generate(const Request& request);
|
||||
virtual void abort(uint64_t id){(void)id;}
|
||||
virtual void open(const QUrl& url){(void)url;};
|
||||
Q_SIGNAL void gotResponse(Response response);
|
||||
@ -68,3 +86,4 @@ public:
|
||||
|
||||
Q_DECLARE_METATYPE(AiBackend::Response);
|
||||
Q_DECLARE_METATYPE(AiBackend::Request);
|
||||
|
||||
|
Reference in New Issue
Block a user