mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-02 09:40:42 +00:00
6d9cdf228c
per model settings as well as the ability to clone a model into a "character." This also implements system prompts as well as quite a few bugfixes for instance this fixes chatgpt.
157 lines
5.3 KiB
C++
157 lines
5.3 KiB
C++
#ifndef CHAT_H
|
|
#define CHAT_H
|
|
|
|
#include <QObject>
|
|
#include <QtQml>
|
|
#include <QDataStream>
|
|
|
|
#include "chatllm.h"
|
|
#include "chatmodel.h"
|
|
#include "database.h"
|
|
|
|
class Chat : public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(QString id READ id NOTIFY idChanged)
|
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
Q_PROPERTY(ChatModel *chatModel READ chatModel NOTIFY chatModelChanged)
|
|
Q_PROPERTY(bool isModelLoaded READ isModelLoaded NOTIFY isModelLoadedChanged)
|
|
Q_PROPERTY(QString response READ response NOTIFY responseChanged)
|
|
Q_PROPERTY(ModelInfo modelInfo READ modelInfo WRITE setModelInfo NOTIFY modelInfoChanged)
|
|
Q_PROPERTY(bool responseInProgress READ responseInProgress NOTIFY responseInProgressChanged)
|
|
Q_PROPERTY(bool isRecalc READ isRecalc NOTIFY recalcChanged)
|
|
Q_PROPERTY(bool isServer READ isServer NOTIFY isServerChanged)
|
|
Q_PROPERTY(QString responseState READ responseState NOTIFY responseStateChanged)
|
|
Q_PROPERTY(QList<QString> collectionList READ collectionList NOTIFY collectionListChanged)
|
|
Q_PROPERTY(QString modelLoadingError READ modelLoadingError NOTIFY modelLoadingErrorChanged)
|
|
Q_PROPERTY(QString tokenSpeed READ tokenSpeed NOTIFY tokenSpeedChanged);
|
|
QML_ELEMENT
|
|
QML_UNCREATABLE("Only creatable from c++!")
|
|
|
|
public:
|
|
enum ResponseState {
|
|
ResponseStopped,
|
|
LocalDocsRetrieval,
|
|
LocalDocsProcessing,
|
|
PromptProcessing,
|
|
ResponseGeneration
|
|
};
|
|
Q_ENUM(ResponseState)
|
|
|
|
explicit Chat(QObject *parent = nullptr);
|
|
explicit Chat(bool isServer, QObject *parent = nullptr);
|
|
virtual ~Chat();
|
|
void connectLLM();
|
|
|
|
QString id() const { return m_id; }
|
|
QString name() const { return m_userName.isEmpty() ? m_name : m_userName; }
|
|
void setName(const QString &name)
|
|
{
|
|
m_userName = name;
|
|
emit nameChanged();
|
|
}
|
|
ChatModel *chatModel() { return m_chatModel; }
|
|
|
|
Q_INVOKABLE void reset();
|
|
Q_INVOKABLE void processSystemPrompt();
|
|
Q_INVOKABLE bool isModelLoaded() const;
|
|
Q_INVOKABLE void prompt(const QString &prompt);
|
|
Q_INVOKABLE void regenerateResponse();
|
|
Q_INVOKABLE void stopGenerating();
|
|
Q_INVOKABLE void newPromptResponsePair(const QString &prompt);
|
|
|
|
QList<ResultInfo> databaseResults() const { return m_databaseResults; }
|
|
|
|
QString response() const;
|
|
bool responseInProgress() const { return m_responseInProgress; }
|
|
QString responseState() const;
|
|
ModelInfo modelInfo() const;
|
|
void setModelInfo(const ModelInfo &modelInfo);
|
|
bool isRecalc() const;
|
|
|
|
void loadDefaultModel();
|
|
void loadModel(const ModelInfo &modelInfo);
|
|
void unloadModel();
|
|
void reloadModel();
|
|
void unloadAndDeleteLater();
|
|
|
|
qint64 creationDate() const { return m_creationDate; }
|
|
bool serialize(QDataStream &stream, int version) const;
|
|
bool deserialize(QDataStream &stream, int version);
|
|
bool isServer() const { return m_isServer; }
|
|
|
|
QList<QString> collectionList() const;
|
|
|
|
Q_INVOKABLE bool hasCollection(const QString &collection) const;
|
|
Q_INVOKABLE void addCollection(const QString &collection);
|
|
Q_INVOKABLE void removeCollection(const QString &collection);
|
|
void resetResponseState();
|
|
|
|
QString modelLoadingError() const { return m_modelLoadingError; }
|
|
|
|
QString tokenSpeed() const { return m_tokenSpeed; }
|
|
|
|
public Q_SLOTS:
|
|
void serverNewPromptResponsePair(const QString &prompt);
|
|
|
|
Q_SIGNALS:
|
|
void idChanged(const QString &id);
|
|
void nameChanged();
|
|
void chatModelChanged();
|
|
void isModelLoadedChanged();
|
|
void responseChanged();
|
|
void responseInProgressChanged();
|
|
void responseStateChanged();
|
|
void promptRequested(const QList<QString> &collectionList, const QString &prompt);
|
|
void regenerateResponseRequested();
|
|
void resetResponseRequested();
|
|
void resetContextRequested();
|
|
void processSystemPromptRequested();
|
|
void modelChangeRequested(const ModelInfo &modelInfo);
|
|
void modelInfoChanged();
|
|
void recalcChanged();
|
|
void loadDefaultModelRequested();
|
|
void loadModelRequested(const ModelInfo &modelInfo);
|
|
void generateNameRequested();
|
|
void modelLoadingErrorChanged();
|
|
void isServerChanged();
|
|
void collectionListChanged(const QList<QString> &collectionList);
|
|
void tokenSpeedChanged();
|
|
|
|
private Q_SLOTS:
|
|
void handleResponseChanged(const QString &response);
|
|
void handleModelLoadedChanged(bool);
|
|
void promptProcessing();
|
|
void responseStopped();
|
|
void generatedNameChanged(const QString &name);
|
|
void handleRecalculating();
|
|
void handleModelLoadingError(const QString &error);
|
|
void handleTokenSpeedChanged(const QString &tokenSpeed);
|
|
void handleDatabaseResultsChanged(const QList<ResultInfo> &results);
|
|
void handleModelInfoChanged(const ModelInfo &modelInfo);
|
|
void handleModelInstalled();
|
|
|
|
private:
|
|
QString m_id;
|
|
QString m_name;
|
|
QString m_generatedName;
|
|
QString m_userName;
|
|
ModelInfo m_modelInfo;
|
|
QString m_modelLoadingError;
|
|
QString m_tokenSpeed;
|
|
QString m_response;
|
|
QList<QString> m_collections;
|
|
ChatModel *m_chatModel;
|
|
bool m_responseInProgress;
|
|
ResponseState m_responseState;
|
|
qint64 m_creationDate;
|
|
ChatLLM *m_llmodel;
|
|
QList<ResultInfo> m_databaseResults;
|
|
bool m_isServer;
|
|
bool m_shouldDeleteLater;
|
|
bool m_isModelLoaded;
|
|
bool m_shouldLoadModelWhenInstalled;
|
|
};
|
|
|
|
#endif // CHAT_H
|