mirror of https://github.com/nomic-ai/gpt4all
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.8 KiB
C
101 lines
2.8 KiB
C
1 year ago
|
#ifndef CHATLLM_H
|
||
|
#define CHATLLM_H
|
||
|
|
||
|
#include <QObject>
|
||
|
#include <QThread>
|
||
|
|
||
|
#include "llmodel/llmodel.h"
|
||
|
|
||
1 year ago
|
class Chat;
|
||
1 year ago
|
class ChatLLM : 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 WRITE setModelName NOTIFY modelNameChanged)
|
||
|
Q_PROPERTY(bool isRecalc READ isRecalc NOTIFY recalcChanged)
|
||
1 year ago
|
Q_PROPERTY(QString generatedName READ generatedName NOTIFY generatedNameChanged)
|
||
1 year ago
|
|
||
|
public:
|
||
1 year ago
|
enum ModelType {
|
||
|
MPT_,
|
||
|
GPTJ_,
|
||
|
LLAMA_
|
||
|
};
|
||
|
|
||
1 year ago
|
ChatLLM(Chat *parent);
|
||
1 year ago
|
|
||
|
bool isModelLoaded() const;
|
||
|
void regenerateResponse();
|
||
|
void resetResponse();
|
||
|
void resetContext();
|
||
|
|
||
|
void stopGenerating() { m_stopGenerating = true; }
|
||
|
|
||
|
QString response() const;
|
||
|
QString modelName() const;
|
||
|
|
||
|
void setModelName(const QString &modelName);
|
||
|
|
||
|
bool isRecalc() const { return m_isRecalc; }
|
||
|
|
||
1 year ago
|
QString generatedName() const { return QString::fromStdString(m_nameResponse); }
|
||
|
|
||
1 year ago
|
bool serialize(QDataStream &stream, int version);
|
||
|
bool deserialize(QDataStream &stream, int version);
|
||
1 year ago
|
|
||
1 year ago
|
public Q_SLOTS:
|
||
1 year ago
|
bool 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,
|
||
|
int32_t n_threads);
|
||
|
bool loadDefaultModel();
|
||
|
bool loadModel(const QString &modelName);
|
||
1 year ago
|
void modelNameChangeRequested(const QString &modelName);
|
||
1 year ago
|
void unloadModel();
|
||
|
void reloadModel(const QString &modelName);
|
||
1 year ago
|
void generateName();
|
||
1 year ago
|
void handleChatIdChanged();
|
||
1 year ago
|
|
||
|
Q_SIGNALS:
|
||
|
void isModelLoadedChanged();
|
||
1 year ago
|
void modelLoadingError(const QString &error);
|
||
1 year ago
|
void responseChanged();
|
||
|
void responseStarted();
|
||
|
void responseStopped();
|
||
|
void modelNameChanged();
|
||
|
void recalcChanged();
|
||
|
void sendStartup();
|
||
|
void sendModelLoaded();
|
||
|
void sendResetContext();
|
||
1 year ago
|
void generatedNameChanged();
|
||
1 year ago
|
void stateChanged();
|
||
1 year ago
|
|
||
|
private:
|
||
|
void resetContextPrivate();
|
||
|
bool handlePrompt(int32_t token);
|
||
|
bool handleResponse(int32_t token, const std::string &response);
|
||
|
bool handleRecalculate(bool isRecalc);
|
||
1 year ago
|
bool handleNamePrompt(int32_t token);
|
||
|
bool handleNameResponse(int32_t token, const std::string &response);
|
||
|
bool handleNameRecalculate(bool isRecalc);
|
||
1 year ago
|
void saveState();
|
||
|
void restoreState();
|
||
1 year ago
|
|
||
|
private:
|
||
|
LLModel::PromptContext m_ctx;
|
||
|
LLModel *m_llmodel;
|
||
|
std::string m_response;
|
||
1 year ago
|
std::string m_nameResponse;
|
||
1 year ago
|
quint32 m_promptResponseTokens;
|
||
|
quint32 m_responseLogits;
|
||
|
QString m_modelName;
|
||
1 year ago
|
ModelType m_modelType;
|
||
1 year ago
|
Chat *m_chat;
|
||
|
QByteArray m_state;
|
||
1 year ago
|
QThread m_llmThread;
|
||
|
std::atomic<bool> m_stopGenerating;
|
||
|
bool m_isRecalc;
|
||
|
};
|
||
|
|
||
|
#endif // CHATLLM_H
|