From c5cbc5a053c517747ebae2560da032be099476f7 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Thu, 3 Aug 2023 19:19:25 +0200 Subject: [PATCH] fixup! add thread summary ui Signed-off-by: hamza221 --- lib/Controller/ThreadController.php | 12 ++++++------ lib/Service/AiIntegrationsService.php | 23 +++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/Controller/ThreadController.php b/lib/Controller/ThreadController.php index 87aba4e616..0e111756ed 100755 --- a/lib/Controller/ThreadController.php +++ b/lib/Controller/ThreadController.php @@ -45,12 +45,12 @@ class ThreadController extends Controller { public function __construct(string $appName, - IRequest $request, - string $UserId, - AccountService $accountService, - IMailManager $mailManager, - AiIntegrationsService $aiIntergrationsService, - LoggerInterface $logger, + IRequest $request, + string $UserId, + AccountService $accountService, + IMailManager $mailManager, + AiIntegrationsService $aiIntergrationsService, + LoggerInterface $logger, ) { parent::__construct($appName, $request); diff --git a/lib/Service/AiIntegrationsService.php b/lib/Service/AiIntegrationsService.php index 96569708c0..ba47d6e6f6 100644 --- a/lib/Service/AiIntegrationsService.php +++ b/lib/Service/AiIntegrationsService.php @@ -27,7 +27,6 @@ use OCP\TextProcessing\IManager; use OCP\TextProcessing\SummaryTaskType; use OCP\TextProcessing\Task; -use OCP\PreConditionNotMetException; use Psr\Container\ContainerInterface; use function array_map; @@ -52,20 +51,20 @@ public function __construct(ContainerInterface $container) { public function summarizeThread(string $threadId, array $messages, string $currentUserId): null|string { try { $manager = $this->container->get(IManager::class); - if(in_array(SummaryTaskType::class, $manager->getAvailableTaskTypes(), true)) { + if(in_array(SummaryTaskType::class, $manager->getAvailableTaskTypes(), true)) { - $messagesBodies = array_map(function ($message) { - return $message->getPreviewText(); - }, $messages); + $messagesBodies = array_map(function ($message) { + return $message->getPreviewText(); + }, $messages); - $taskPrompt = implode("\n", $messagesBodies); - $summaryTask = new Task(SummaryTaskType::class, $taskPrompt, "mail", $currentUserId, $threadId); - $manager->runTask($summaryTask); + $taskPrompt = implode("\n", $messagesBodies); + $summaryTask = new Task(SummaryTaskType::class, $taskPrompt, "mail", $currentUserId, $threadId); + $manager->runTask($summaryTask); - return $summaryTask->getOutput(); - } else { - throw new ServiceException('No language model available for summary'); - } + return $summaryTask->getOutput(); + } else { + throw new ServiceException('No language model available for summary'); + } } catch (\Throwable $e) { throw new ServiceException('Text processing is not available in your current Nextcloud version'); }