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.
|
|
|
|
|
const char* dummy_summary = "This is a summary of the oldest 20 messages.";
|
|
|
|
|
char* result = malloc(strlen(dummy_summary) + 1);
|
|
|
|
|
if (result) {
|
|
|
|
|
strcpy(result, dummy_summary);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
concatenated[0] = '\0';
|
|
|
|
|
for (size_t i = start_index; i < message_count; ++i) {
|
|
|
|
|
strcat(concatenated, messages[i]);
|
|
|
|
|
if (i < message_count - 1) {
|
|
|
|
|
strcat(concatenated, " "); // separator
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Call the LLM API to get the summary
|
|
|
|
|
char* summary = call_llm_to_summarize(concatenated);
|
|
|
|
|
free(concatenated);
|
|
|
|
|
return summary;
|
|
|
|
|
}
|