diff --git a/lib/TaskProcessing/SummaryProvider.php b/lib/TaskProcessing/SummaryProvider.php index a9cf3d5c..9356e134 100644 --- a/lib/TaskProcessing/SummaryProvider.php +++ b/lib/TaskProcessing/SummaryProvider.php @@ -126,7 +126,8 @@ public function process(?string $userId, array $input, callable $reportProgress) try { $completions = []; if ($this->openAiAPIService->isUsingOpenAi() || $this->openAiSettingsService->getChatEndpointEnabled()) { - $summarySystemPrompt = 'Summarize the following text in the same language as the text.'; + $summarySystemPrompt = 'You are a helpful assistant that summarizes text in the same language as the text. ' . + 'You should only return the summary without any additional information.'; foreach ($prompts as $p) { $completion = $this->openAiAPIService->createChatCompletion($userId, $model, $p, $summarySystemPrompt, null, 1, $maxTokens); @@ -134,7 +135,9 @@ public function process(?string $userId, array $input, callable $reportProgress) } } else { $wrapSummaryPrompt = function (string $p): string { - return 'Summarize the following text delimited by XML tags in the same language as the text.\n\n\n' . $p . '\n'; + return 'You are a helpful assistant that summarizes text in the same language as the text. ' . + 'You should only return the summary without any additional information. ' . + 'Here is the text to summarize:\n\n' . $p . '\n'; }; foreach (array_map($wrapSummaryPrompt, $prompts) as $p) { diff --git a/tests/unit/Providers/OpenAiProviderTest.php b/tests/unit/Providers/OpenAiProviderTest.php index 74833fe0..d3c1435f 100644 --- a/tests/unit/Providers/OpenAiProviderTest.php +++ b/tests/unit/Providers/OpenAiProviderTest.php @@ -391,7 +391,8 @@ public function testSummaryProvider(): void { $url = self::OPENAI_API_BASE . 'chat/completions'; $options = ['timeout' => Application::OPENAI_DEFAULT_REQUEST_TIMEOUT, 'headers' => ['User-Agent' => Application::USER_AGENT, 'Authorization' => self::AUTHORIZATION_HEADER, 'Content-Type' => 'application/json']]; - $systemPrompt = 'Summarize the following text in the same language as the text.'; + $systemPrompt = 'You are a helpful assistant that summarizes text in the same language as the text. ' . + 'You should only return the summary without any additional information.'; $options['body'] = json_encode([ 'model' => Application::DEFAULT_COMPLETION_MODEL_ID, 'messages' => [['role' => 'system', 'content' => $systemPrompt],