-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathllamachatmessage.h
More file actions
89 lines (73 loc) · 2.42 KB
/
llamachatmessage.h
File metadata and controls
89 lines (73 loc) · 2.42 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <QLabel>
#include <QVBoxLayout>
#include <QVector>
#include <QWidget>
#include "llamachatmanager.h"
#include "llamatypes.h"
class QToolButton;
class QPushButton;
namespace LlamaCpp {
class MarkdownLabel;
class ChatMessage : public QWidget
{
Q_OBJECT
public:
explicit ChatMessage(const Message &msg,
const QVector<qint64> &siblingLeafIds,
int siblingIdx,
QWidget *parent = nullptr);
Message &message() { return m_msg; }
void renderMarkdown(const QString &text, bool forceUpdate = false);
void messageCompleted(bool completed);
bool isUser() const;
void setSiblingLeafIds(const QVector<qint64> &newSiblingLeafIds);
void setSiblingIdx(int newSiblingIdx);
QString plainText() const;
void highlightAllMatches(const QString &query);
void highlightMatch(int start, int length, bool selected = true);
void clearHighlight();
bool isTool() const;
signals:
void regenerateRequested(const Message &msg);
void editRequested(const Message &msg);
void siblingChanged(qint64 siblingId);
void deleteRequested(const Message &msg);
private slots:
void onCopyClicked();
void onEditClicked();
void onRegenerateClicked();
void onPrevSiblingClicked();
void onNextSiblingClicked();
void onCopyToClipboard(const QString &verbatimCode, const QString &highlightedCode);
void onSaveToDisk(const QString &fileName, const QString &verbatimCode);
void onDeleteClicked();
private:
void buildUI();
void updateUI();
void resizeEvent(QResizeEvent *ev) override;
bool eventFilter(QObject *obj, QEvent *event) override;
void applyStyleSheet();
QString getToolUsageAndResult() const;
bool haveToolCalls() const;
Message m_msg;
QVector<qint64> m_siblingLeafIds;
int m_siblingIdx{1};
bool m_isUser;
bool m_isTool = false;
// UI
QLabel *m_bubble{nullptr};
QToolButton *m_copyButton{nullptr};
QToolButton *m_editButton{nullptr};
QToolButton *m_regenButton{nullptr};
QToolButton *m_prevButton{nullptr};
QToolButton *m_nextButton{nullptr};
QToolButton *m_attachedFiles{nullptr};
QToolButton *m_deleteButton{nullptr};
QLabel *m_siblingLabel{nullptr};
MarkdownLabel *m_markdownLabel{nullptr};
QVBoxLayout *m_mainLayout{nullptr};
bool m_isToolCall{false};
bool m_haveToolCalls{false};
};
} // namespace LlamaCpp