forked from cristianadam/llama.qtcreator
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathllamatypes.h
More file actions
140 lines (122 loc) · 3.12 KB
/
llamatypes.h
File metadata and controls
140 lines (122 loc) · 3.12 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include <QDateTime>
#include <QJsonObject>
#include <QMap>
#include <QString>
#include <QVariant>
#include <QVector>
namespace LlamaCpp {
struct TimingReport
{
double prompt_n{0};
double prompt_ms{0};
double predicted_n{0};
double predicted_ms{0};
};
struct PromptProgress
{
int total{0};
int cache{0};
int processed{0};
qint64 time_ms{0};
};
/**
* What is conversation "branching"? It is a feature that allows the user to edit an old message
* in the history, while still keeping the conversation flow.
* Inspired by ChatGPT / Claude / Hugging Chat where you edit a message, a new branch of the
* conversation is created, and the old message is still visible.
*
* We use the same node-based structure like other chat UIs, where each message has a parent
* and children. A "root" message is the first message in a conversation, which will not be
* displayed in the UI.
*
* root
* ├── message 1
* │ └── message 2
* │ └── message 3
* └── message 4
* └── message 5
*
* In the above example, assuming that user wants to edit message 2, a new branch will be created:
*
* ├── message 2
* │ └── message 3
* └── message 6
*
* Message 2 and 6 are siblings, and message 6 is the new branch.
*
* We only need to know the last node (aka leaf) to get the current branch. In the above example,
* message 5 is the leaf of branch containing message 4 and 5.
*
*/
struct Message
{
qint64 id; // 64‑bit is plenty
QString convId;
QString type; // "text" | "root"
qint64 timestamp; // from QDateTime::currentMSecsSinceEpoch()
QString role; // "user" | "assistant" | "system" | "tool"
QString content;
TimingReport timings;
PromptProgress promptProgress;
QList<QVariantMap> extra; // array of MessageExtra
// Node relations – stored in the DB, not serialised directly
qint64 parent;
QList<qint64> children;
bool haveContent = false;
};
struct MessageExtraTextFile
{
QString type = "textFile";
QString name;
QString content;
};
struct MessageExtraImageFile
{
QString type = "imageFile";
QString name;
QString base64Url;
};
struct MessageExtraAudioFile
{
QString type = "audioFile";
QString name;
QString base64Data;
QString mimeType;
};
struct MessageExtraContext
{
QString type = "context";
QString name;
QString content;
};
using APIMessageContentPart = QJsonObject; // will contain type, text, image_url, etc.
struct APIMessage
{
QString role;
QVariant content; // QString or QList<APIMessageContentPart>
};
struct Conversation
{
QString id; // e.g. “conv-1234567890”
qint64 lastModified{-1};
qint64 currNode{-1}; // id of the node currently shown
QString name;
};
struct ViewingChat
{
Conversation conv;
QVector<Message> messages;
};
struct LlamaCppServerProps
{
QString build_info;
QString model_path;
int n_ctx = 0;
struct Modalities
{
bool vision = false;
bool audio = false;
} modalities;
};
} // namespace LLamaCpp