2023-04-09 03:28:39 +00:00
|
|
|
#ifndef LLM_H
|
|
|
|
#define LLM_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QThread>
|
|
|
|
#include "gptj.h"
|
|
|
|
|
|
|
|
class GPTJObject : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool isModelLoaded READ isModelLoaded NOTIFY isModelLoadedChanged)
|
|
|
|
Q_PROPERTY(QString response READ response NOTIFY responseChanged)
|
2023-04-11 12:29:55 +00:00
|
|
|
Q_PROPERTY(QString modelName READ modelName NOTIFY modelNameChanged)
|
2023-04-09 03:28:39 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
GPTJObject();
|
|
|
|
|
|
|
|
bool loadModel();
|
|
|
|
bool isModelLoaded() const;
|
|
|
|
void resetResponse();
|
2023-04-10 21:13:22 +00:00
|
|
|
void resetContext();
|
2023-04-09 03:28:39 +00:00
|
|
|
void stopGenerating() { m_stopGenerating = true; }
|
|
|
|
|
|
|
|
QString response() const;
|
2023-04-11 12:29:55 +00:00
|
|
|
QString modelName() const;
|
2023-04-09 03:28:39 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
bool prompt(const QString &prompt);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void isModelLoadedChanged();
|
|
|
|
void responseChanged();
|
|
|
|
void responseStarted();
|
|
|
|
void responseStopped();
|
2023-04-11 12:29:55 +00:00
|
|
|
void modelNameChanged();
|
2023-04-09 03:28:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool handleResponse(const std::string &response);
|
|
|
|
|
|
|
|
private:
|
|
|
|
GPTJ *m_gptj;
|
|
|
|
std::string m_response;
|
2023-04-11 12:29:55 +00:00
|
|
|
QString m_modelName;
|
2023-04-09 03:28:39 +00:00
|
|
|
QThread m_llmThread;
|
|
|
|
std::atomic<bool> m_stopGenerating;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LLM : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool isModelLoaded READ isModelLoaded NOTIFY isModelLoadedChanged)
|
|
|
|
Q_PROPERTY(QString response READ response NOTIFY responseChanged)
|
2023-04-11 12:29:55 +00:00
|
|
|
Q_PROPERTY(QString modelName READ modelName NOTIFY modelNameChanged)
|
2023-04-09 03:28:39 +00:00
|
|
|
Q_PROPERTY(bool responseInProgress READ responseInProgress NOTIFY responseInProgressChanged)
|
|
|
|
public:
|
|
|
|
|
|
|
|
static LLM *globalInstance();
|
|
|
|
|
|
|
|
Q_INVOKABLE bool isModelLoaded() const;
|
|
|
|
Q_INVOKABLE void prompt(const QString &prompt);
|
2023-04-10 21:13:22 +00:00
|
|
|
Q_INVOKABLE void resetContext();
|
2023-04-09 03:28:39 +00:00
|
|
|
Q_INVOKABLE void resetResponse();
|
|
|
|
Q_INVOKABLE void stopGenerating();
|
|
|
|
|
|
|
|
QString response() const;
|
|
|
|
bool responseInProgress() const { return m_responseInProgress; }
|
|
|
|
|
2023-04-11 12:29:55 +00:00
|
|
|
QString modelName() const;
|
|
|
|
|
2023-04-11 03:34:34 +00:00
|
|
|
Q_INVOKABLE bool checkForUpdates() const;
|
|
|
|
|
2023-04-09 03:28:39 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void isModelLoadedChanged();
|
|
|
|
void responseChanged();
|
|
|
|
void responseInProgressChanged();
|
|
|
|
void promptRequested(const QString &prompt);
|
|
|
|
void resetResponseRequested();
|
2023-04-10 21:13:22 +00:00
|
|
|
void resetContextRequested();
|
2023-04-11 12:29:55 +00:00
|
|
|
void modelNameChanged();
|
2023-04-09 03:28:39 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void responseStarted();
|
|
|
|
void responseStopped();
|
|
|
|
|
|
|
|
private:
|
|
|
|
GPTJObject *m_gptj;
|
|
|
|
bool m_responseInProgress;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit LLM();
|
|
|
|
~LLM() {}
|
|
|
|
friend class MyLLM;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LLM_H
|