-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathopenai_message.h
71 lines (57 loc) · 1.51 KB
/
openai_message.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
#pragma once
#include <QObject>
#include <QtQml>
class OpenAIMessage: public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("OpenAIMessage is not creatable")
Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged)
Q_PROPERTY(Role role READ role WRITE setRole NOTIFY roleChanged)
Q_ENUMS(Role)
public:
enum class Role {
System,
User,
Assistant
};
explicit OpenAIMessage(QObject *parent = nullptr);
explicit OpenAIMessage(const QString& content, Role role, QObject *parent = nullptr);
~OpenAIMessage();
inline static QString roleToString(Role role)
{
switch (role) {
case Role::System:
return "system";
case Role::User:
return "user";
case Role::Assistant:
return "assistant";
default:
return "unknown";
}
}
inline static Role roleFromString(const QString& role)
{
if (role == "system") {
return Role::System;
} else if (role == "user") {
return Role::User;
} else if (role == "assistant") {
return Role::Assistant;
} else {
return Role::System;
}
}
public slots:
QString content() const;
void setContent(const QString& content);
Role role() const;
void setRole(Role role);
signals:
void contentChanged();
void roleChanged();
private:
QString m_content;
Role m_role;
};