Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/Service/RecordingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -455,15 +456,24 @@ public function storeTranscript(string $owner, string $roomToken, int $recording
return;
}

$customSummarizePrompt = $this->serverConfig->getAppValue('spreed', 'call_recording_summary_prompt', '');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$customSummarizePrompt = $this->serverConfig->getAppValue('spreed', 'call_recording_summary_prompt', '');
$customSummarizePrompt = $this->appConfig->getAppValueString('call_recording_summary_prompt');

And can we should add it to the ConfigLexicon class.

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,
Expand Down
58 changes: 58 additions & 0 deletions tests/php/Service/RecordingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
}
}
Loading