diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index 0f70e3848aa..037373ddcbe 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -45,6 +45,7 @@ use OCP\TaskProcessing\IManager as ITaskProcessingManager; use OCP\TaskProcessing\Task; use OCP\TaskProcessing\TaskTypes\AudioToText; +use OCP\TaskProcessing\TaskTypes\TextToText; use OCP\TaskProcessing\TaskTypes\TextToTextSummary; use Psr\Log\LoggerInterface; @@ -455,15 +456,24 @@ public function storeTranscript(string $owner, string $roomToken, int $recording return; } + $customSummarizePrompt = $this->serverConfig->getAppValue('spreed', 'call_recording_summary_prompt', ''); + if ($customSummarizePrompt !== '') { + $taskType = TextToText::ID; + $input = $customSummarizePrompt . "\n" . $output; + } else { + $taskType = TextToTextSummary::ID; + $input = $output; + } + $supportedTaskTypeIds = $this->taskProcessingManager->getAvailableTaskTypeIds(); - if (!in_array(TextToTextSummary::ID, $supportedTaskTypeIds, true)) { - $this->logger->error('Can not summarize call recording as no TextToTextSummary task provider is available'); + if (!in_array($taskType, $supportedTaskTypeIds, true)) { + $this->logger->error('Can not summarize call recording as no ' . $taskType . ' task provider is available'); return; } $task = new Task( - TextToTextSummary::ID, - ['input' => $output], + $taskType, + ['input' => $input], Application::APP_ID, $owner, 'call/summary/' . $room->getToken() . '/' . $recordingFileId, diff --git a/tests/php/Service/RecordingServiceTest.php b/tests/php/Service/RecordingServiceTest.php index 57d32092451..7cb518fc775 100644 --- a/tests/php/Service/RecordingServiceTest.php +++ b/tests/php/Service/RecordingServiceTest.php @@ -47,6 +47,8 @@ function is_uploaded_file($filename) { use OCP\Share\IShare; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\TaskProcessing\IManager as ITaskProcessingManager; +use OCP\TaskProcessing\Task; +use OCP\TaskProcessing\TaskTypes\TextToText; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -405,4 +407,60 @@ public function testFinishUploadInvalidFormat(): void { $this->expectExceptionMessage('file_mimetype'); $this->recordingService->finishUpload($room, $owner, 'name.ogg'); } + + public function testStoreTranscriptWithCustomPrompt(): void { + $owner = 'user1'; + $roomToken = 'token123'; + $recordingFileId = 42; + $output = 'This is the transcript contents.'; + $aiTask = 'transcript'; + $customPrompt = 'Summarize this transcript:'; + + $userFolder = $this->createMock(Folder::class); + $this->rootFolder->method('getUserFolder')->with($owner)->willReturn($userFolder); + $recordingFolder = $this->createMock(Folder::class); + $recordingFolder->method('getName')->willReturn($roomToken); + $recording = $this->createMock(File::class); + $recording->method('getName')->willReturn('recording.ogg'); + $recording->method('getParent')->willReturn($recordingFolder); + $userFolder->method('getById')->with($recordingFileId)->willReturn([$recording]); + + $room = $this->createRoom($roomToken); + $participant = $this->createParticipant($room, $owner); + $this->roomManager->method('getRoomForUserByToken')->with($roomToken, $owner)->willReturn($room); + $this->participantService->method('getParticipant')->with($room, $owner)->willReturn($participant); + + $this->serverConfig->method('getAppValue') + ->willReturnCallback( + function (string $app, string $key, string $default = '') use ($customPrompt): string { + if ($key === 'call_recording_summary_prompt') { + return $customPrompt; + } + + return $default; + } + ); + + $this->taskProcessingManager->method('getAvailableTaskTypeIds')->willReturn([TextToText::ID]); + $this->taskProcessingManager->expects($this->once())->method('scheduleTask') + ->with($this->callback( + function (Task $task) use ($customPrompt, $output): bool { + if ($task->getTaskTypeId() !== TextToText::ID) { + return false; + } + + return $task->getInput() === [ + 'input' => $customPrompt . "\n" . $output, + ]; + } + )); + + $this->recordingService->storeTranscript( + $owner, + $roomToken, + $recordingFileId, + $output, + $aiTask, + ); + } }