-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompress.cpp
More file actions
27 lines (23 loc) · 969 Bytes
/
Copy pathcompress.cpp
File metadata and controls
27 lines (23 loc) · 969 Bytes
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
#define LLM_COMPRESS_IMPLEMENTATION
#include "llm_compress.hpp"
#include <cstdio>
int main() {
std::string q;
for (int i = 0; i < 8; ++i) q += "why is my iterator invalid? ";
std::vector<llm::CompressMessage> history = {
{"system", "You are a terse C++ reviewer."}};
for (int i = 1; i <= 12; ++i) {
auto n = std::to_string(i);
history.push_back({"user", "Q" + n + ": " + q});
history.push_back({"assistant", "A" + n + ": push_back reallocated."});
}
llm::CompressConfig cfg;
cfg.strategy = llm::SlidingWindow{3}; // keep the last 3 turns
cfg.token_budget = 1000;
auto r = llm::compress_messages(history, cfg);
std::printf("tokens %zu -> %zu, dropped %zu of %zu messages\n\n",
r.tokens_before, r.tokens_after, r.messages_removed,
history.size());
for (const auto& m : r.messages)
std::printf("%-9s %.40s\n", m.role.c_str(), m.content.c_str());
}