Skip to content

Commit 70d0a43

Browse files
committed
feat: add chatlogs of outdated summaries and adjust summary prompt
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
1 parent 198bc13 commit 70d0a43

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/Service/SessionSummaryService.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function generateSummaries(array $sessions): void {
4949
array_shift($messages);
5050
}
5151

52-
$prompt = "Summarize insights about the user's circumstances, preferences and choices from the following conversation. Be as concise as possible. Do not add an introductory sentence or any other remarks.\n\n";
52+
$prompt = "Summarize insights about the user's circumstances, preferences and choices from the following conversation. Be as concise as possible. Especially mention any facts or numbers stated by the user. Do not add an introductory sentence or any other remarks.\n\n";
5353

5454
foreach ($messages as $message) {
5555
$prompt .= $message->getRole() . ': ' . $message->getContent() . "\n\n";
@@ -118,14 +118,20 @@ public function getMemories(?string $userId): array {
118118
$sessions = $this->sessionMapper->getRememberedUserSessions($userId, self::MAX_INJECTED_SUMMARIES);
119119
foreach ($sessions as $session) {
120120
if ($session->getSummary() !== null) {
121-
$memories[] = $session->getSummary();
121+
$memory = $session->getSummary();
122+
if (!$session->getIsSummaryUpToDate()) {
123+
$lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10'));
124+
$chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages);
125+
$memory .= "The summary is outdated. These are the last messages in the raw chat history: " . json_encode($chatHistory);
126+
}
122127

123128
}
124129
else {
125130
$lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10'));
126131
$chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages);
127-
$memories[] = "This is the raw chat history of a chat between the user and Assistant: " . json_encode($chatHistory);
132+
$memory = "This is the raw chat history of a chat between the user and Assistant: " . json_encode($chatHistory);
128133
}
134+
$memories[] = $memory;
129135
}
130136
return $memories;
131137
} catch (Exception $e) {

0 commit comments

Comments
 (0)