This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathllm.h
96 lines (75 loc) · 2.27 KB
/
llm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef LLM_H
#define LLM_H
#include <QObject>
#include <QThread>
#include "gptj.h"
class LLMObject : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isModelLoaded READ isModelLoaded NOTIFY isModelLoadedChanged)
Q_PROPERTY(QString response READ response NOTIFY responseChanged)
Q_PROPERTY(QString modelName READ modelName NOTIFY modelNameChanged)
public:
LLMObject();
bool loadModel();
bool isModelLoaded() const;
void resetResponse();
void resetContext();
void stopGenerating() { m_stopGenerating = true; }
QString response() const;
QString modelName() const;
public Q_SLOTS:
bool prompt(const QString &prompt);
Q_SIGNALS:
void isModelLoadedChanged();
void responseChanged();
void responseStarted();
void responseStopped();
void modelNameChanged();
private:
bool handleResponse(const std::string &response);
private:
LLModel *m_llmodel;
std::string m_response;
QString m_modelName;
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)
Q_PROPERTY(QString modelName READ modelName NOTIFY modelNameChanged)
Q_PROPERTY(bool responseInProgress READ responseInProgress NOTIFY responseInProgressChanged)
public:
static LLM *globalInstance();
Q_INVOKABLE bool isModelLoaded() const;
Q_INVOKABLE void prompt(const QString &prompt);
Q_INVOKABLE void resetContext();
Q_INVOKABLE void resetResponse();
Q_INVOKABLE void stopGenerating();
QString response() const;
bool responseInProgress() const { return m_responseInProgress; }
QString modelName() const;
Q_INVOKABLE bool checkForUpdates() const;
Q_SIGNALS:
void isModelLoadedChanged();
void responseChanged();
void responseInProgressChanged();
void promptRequested(const QString &prompt);
void resetResponseRequested();
void resetContextRequested();
void modelNameChanged();
private Q_SLOTS:
void responseStarted();
void responseStopped();
private:
LLMObject *m_llmodel;
bool m_responseInProgress;
private:
explicit LLM();
~LLM() {}
friend class MyLLM;
};
#endif // LLM_H