llm-chat 0.0.0
LLM-Chat
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1#pragma once
2
3#include <QAbstractListModel>
4#include <QDateTime>
5#include <QSortFilterProxyModel>
6#include <QVector>
7
8namespace llm_chat {
9
10class Message;
11
13class Thread : public QAbstractListModel {
14 Q_OBJECT
15 Q_PROPERTY(QList<Message *> messages READ messages CONSTANT FINAL)
16 Q_PROPERTY(QDateTime createdAt READ createdAt CONSTANT FINAL)
17
18 public:
26
29 explicit Thread(QObject *parent = nullptr);
30
33 [[nodiscard]] int rowCount(
34 const QModelIndex &parent = QModelIndex()) const override;
39 [[nodiscard]] QVariant data(const QModelIndex &index,
40 int role = Qt::DisplayRole) const override;
43 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
49 Q_INVOKABLE void addMessage(const QString &text, bool is_user,
50 const QVector<QVariant> &context = {},
51 const bool in_progress = false);
52
55 [[nodiscard]] inline const QList<Message *> &messages() const {
56 return m_Messages;
57 }
59 void clearMessages();
60
63 [[nodiscard]] inline const QDateTime &createdAt() const {
64 return m_CreatedAt;
65 }
66
69
70 private:
71 QList<Message *> m_Messages;
72 QDateTime m_CreatedAt;
73};
74
75} // namespace llm_chat
The Thread class provides a model for the chat interface.
Definition thread.h:13
void removeLatestMessage()
Removes the latest message from the model.
Definition thread.cpp:61
Thread(QObject *parent=nullptr)
Constructs a new Thread object.
Definition thread.cpp:10
const QDateTime & createdAt() const
Returns the creation time of the chat thread.
Definition thread.h:63
MessageRoles
The data roles for the model.
Definition thread.h:20
@ ContextRole
Definition thread.h:23
@ TextRole
Definition thread.h:21
@ FinishedRole
Definition thread.h:24
@ IsUserRole
Definition thread.h:22
Q_INVOKABLE void addMessage(const QString &text, bool is_user, const QVector< QVariant > &context={}, const bool in_progress=false)
Adds a new message to the model.
Definition thread.cpp:46
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
Definition thread.cpp:19
QDateTime createdAt
Definition thread.h:16
const QList< Message * > & messages() const
Returns the list of messages.
Definition thread.h:55
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
Definition thread.cpp:14
void clearMessages()
Clears the list of messages.
Definition thread.cpp:54
QHash< int, QByteArray > roleNames() const override
Returns the role names for the model.
Definition thread.cpp:37
QList< Message * > messages
Definition thread.h:15
Definition backend.cpp:11