-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathopenai_message_model.h
51 lines (39 loc) · 1.46 KB
/
openai_message_model.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
#pragma once
#include <QObject>
#include <QAbstractListModel>
#include <QtQml>
#include "openai_message.h"
class OpenAIMessageModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QList<OpenAIMessage*> messages READ messages WRITE setMessages NOTIFY messagesChanged)
Q_PROPERTY(QString jsonString READ jsonString WRITE setJsonString NOTIFY jsonStringChanged)
public:
enum Role {
MessageRole = Qt::UserRole + 1,
RoleRole
};
explicit OpenAIMessageModel(QObject *parent = nullptr);
~OpenAIMessageModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
QList<OpenAIMessage *> messages() const;
void setMessages(const QList<OpenAIMessage *> &newMessages);
QString jsonString() const;
void setJsonString(const QString &newJsonString);
public slots:
void addMessage(OpenAIMessage::Role role, const QString& content);
void addMessage(OpenAIMessage *message);
void removeMessage(OpenAIMessage *message);
void clearMessages();
signals:
void messagesChanged();
void jsonStringChanged();
private:
QList<OpenAIMessage*> m_messages;
QString m_jsonString;
QList<OpenAIMessage*> messagesFromJson(const QString &jsonString) const;
QString jsonFromMessages(const QList<OpenAIMessage*> &messages) const;
};