2023-05-01 00:28:07 +00:00
|
|
|
#ifndef CHAT_H
|
|
|
|
#define CHAT_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtQml>
|
|
|
|
|
2023-05-01 13:10:05 +00:00
|
|
|
#include "chatllm.h"
|
2023-05-01 00:28:07 +00:00
|
|
|
#include "chatmodel.h"
|
|
|
|
|
|
|
|
class Chat : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString id READ id NOTIFY idChanged)
|
2023-05-02 00:27:07 +00:00
|
|
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
2023-05-01 00:28:07 +00:00
|
|
|
Q_PROPERTY(ChatModel *chatModel READ chatModel NOTIFY chatModelChanged)
|
2023-05-01 13:10:05 +00:00
|
|
|
Q_PROPERTY(bool isModelLoaded READ isModelLoaded NOTIFY isModelLoadedChanged)
|
|
|
|
Q_PROPERTY(QString response READ response NOTIFY responseChanged)
|
|
|
|
Q_PROPERTY(QString modelName READ modelName WRITE setModelName NOTIFY modelNameChanged)
|
|
|
|
Q_PROPERTY(bool responseInProgress READ responseInProgress NOTIFY responseInProgressChanged)
|
|
|
|
Q_PROPERTY(int32_t threadCount READ threadCount WRITE setThreadCount NOTIFY threadCountChanged)
|
|
|
|
Q_PROPERTY(bool isRecalc READ isRecalc NOTIFY recalcChanged)
|
2023-05-01 00:28:07 +00:00
|
|
|
QML_ELEMENT
|
|
|
|
QML_UNCREATABLE("Only creatable from c++!")
|
|
|
|
|
|
|
|
public:
|
2023-05-01 13:10:05 +00:00
|
|
|
explicit Chat(QObject *parent = nullptr);
|
2023-05-01 00:28:07 +00:00
|
|
|
|
|
|
|
QString id() const { return m_id; }
|
2023-05-02 00:27:07 +00:00
|
|
|
QString name() const { return m_userName.isEmpty() ? m_name : m_userName; }
|
|
|
|
void setName(const QString &name)
|
|
|
|
{
|
|
|
|
m_userName = name;
|
|
|
|
emit nameChanged();
|
|
|
|
}
|
2023-05-01 00:28:07 +00:00
|
|
|
ChatModel *chatModel() { return m_chatModel; }
|
|
|
|
|
2023-05-01 13:10:05 +00:00
|
|
|
Q_INVOKABLE void reset();
|
|
|
|
Q_INVOKABLE bool isModelLoaded() const;
|
|
|
|
Q_INVOKABLE void prompt(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
|
|
|
|
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens);
|
|
|
|
Q_INVOKABLE void regenerateResponse();
|
|
|
|
Q_INVOKABLE void stopGenerating();
|
|
|
|
Q_INVOKABLE void syncThreadCount();
|
|
|
|
Q_INVOKABLE void setThreadCount(int32_t n_threads);
|
|
|
|
Q_INVOKABLE int32_t threadCount();
|
2023-05-01 16:30:54 +00:00
|
|
|
Q_INVOKABLE void newPromptResponsePair(const QString &prompt);
|
2023-05-01 13:10:05 +00:00
|
|
|
|
|
|
|
QString response() const;
|
|
|
|
bool responseInProgress() const { return m_responseInProgress; }
|
|
|
|
QString modelName() const;
|
|
|
|
void setModelName(const QString &modelName);
|
|
|
|
bool isRecalc() const;
|
2023-05-01 01:05:54 +00:00
|
|
|
|
2023-05-02 00:27:07 +00:00
|
|
|
void unload();
|
|
|
|
void reload();
|
|
|
|
|
2023-05-01 00:28:07 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void idChanged();
|
|
|
|
void nameChanged();
|
|
|
|
void chatModelChanged();
|
2023-05-01 13:10:05 +00:00
|
|
|
void isModelLoadedChanged();
|
|
|
|
void responseChanged();
|
|
|
|
void responseInProgressChanged();
|
|
|
|
void promptRequested(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
|
|
|
|
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens);
|
|
|
|
void regenerateResponseRequested();
|
|
|
|
void resetResponseRequested();
|
|
|
|
void resetContextRequested();
|
|
|
|
void modelNameChangeRequested(const QString &modelName);
|
|
|
|
void modelNameChanged();
|
|
|
|
void threadCountChanged();
|
|
|
|
void setThreadCountRequested(int32_t threadCount);
|
|
|
|
void recalcChanged();
|
2023-05-02 00:27:07 +00:00
|
|
|
void unloadRequested();
|
|
|
|
void reloadRequested();
|
2023-05-01 13:10:05 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void responseStarted();
|
|
|
|
void responseStopped();
|
2023-05-01 00:28:07 +00:00
|
|
|
|
|
|
|
private:
|
2023-05-01 13:10:05 +00:00
|
|
|
ChatLLM *m_llmodel;
|
2023-05-01 00:28:07 +00:00
|
|
|
QString m_id;
|
|
|
|
QString m_name;
|
2023-05-02 00:27:07 +00:00
|
|
|
QString m_userName;
|
2023-05-01 00:28:07 +00:00
|
|
|
ChatModel *m_chatModel;
|
2023-05-01 13:10:05 +00:00
|
|
|
bool m_responseInProgress;
|
|
|
|
int32_t m_desiredThreadCount;
|
2023-05-01 00:28:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CHAT_H
|