2026-02-10 04:29:48 +01:00
|
|
|
// retoor <retoor@molodetz.nl>
|
2026-01-29 02:21:11 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
// Placeholder for LLM API call
|
|
|
|
|
// In a real implementation, this function would call the LLM API to get the summary.
|
|
|
|
|
static char* call_llm_to_summarize(const char* messages_concatenated) {
|
|
|
|
|
// For demonstration, just return a dummy summary.
|
2026-04-03 10:42:43 +02:00
|
|
|
return strdup("This is a summary of the oldest 20 messages.");
|
2026-01-29 02:21:11 +01:00
|
|
|
}
|
|
|
|
|
char* summarize_oldest_messages(const char** messages, size_t message_count) {
|
|
|
|
|
// Concatenate the oldest 20 messages
|
|
|
|
|
size_t total_length = 0;
|
|
|
|
|
size_t start_index = 0;
|
|
|
|
|
if (message_count > 20) {
|
|
|
|
|
start_index = message_count - 20;
|
|
|
|
|
}
|
|
|
|
|
for (size_t i = start_index; i < message_count; ++i) {
|
|
|
|
|
total_length += strlen(messages[i]) + 1; // +1 for separator
|
|
|
|
|
}
|
|
|
|
|
char* concatenated = malloc(total_length + 1);
|
|
|
|
|
if (!concatenated) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2026-04-03 10:42:43 +02:00
|
|
|
size_t write_offset = 0;
|
2026-01-29 02:21:11 +01:00
|
|
|
for (size_t i = start_index; i < message_count; ++i) {
|
2026-04-03 10:42:43 +02:00
|
|
|
size_t msg_len = strlen(messages[i]);
|
|
|
|
|
memcpy(concatenated + write_offset, messages[i], msg_len);
|
|
|
|
|
write_offset += msg_len;
|
2026-01-29 02:21:11 +01:00
|
|
|
if (i < message_count - 1) {
|
2026-04-03 10:42:43 +02:00
|
|
|
concatenated[write_offset++] = ' ';
|
2026-01-29 02:21:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-03 10:42:43 +02:00
|
|
|
concatenated[write_offset] = '\0';
|
2026-01-29 02:21:11 +01:00
|
|
|
// Call the LLM API to get the summary
|
|
|
|
|
char* summary = call_llm_to_summarize(concatenated);
|
|
|
|
|
free(concatenated);
|
|
|
|
|
return summary;
|
|
|
|
|
}
|