|
13 | 13 | use OCA\Richdocuments\TaskProcessing\Presentation\Slides\TitleSlide; |
14 | 14 | use OCA\Richdocuments\TemplateManager; |
15 | 15 | use OCP\IConfig; |
| 16 | +use OCP\IL10N; |
16 | 17 | use OCP\TaskProcessing\Exception\Exception; |
17 | 18 | use OCP\TaskProcessing\Exception\PreConditionNotMetException; |
18 | 19 | use OCP\TaskProcessing\Exception\UnauthorizedException; |
@@ -70,17 +71,18 @@ public function __construct( |
70 | 71 | private TemplateManager $templateManager, |
71 | 72 | private RemoteService $remoteService, |
72 | 73 | private IConfig $config, |
| 74 | + private IL10N $l10n, |
73 | 75 | ) { |
74 | 76 | } |
75 | 77 |
|
76 | | - public function generateSlideDeck(?string $userId, string $presentationText) { |
| 78 | + public function generateSlideDeck(?string $userId, string $presentationText, bool $includeWatermark = true) { |
77 | 79 | $rawModelOutput = $this->runLLMQuery($userId, $presentationText); |
78 | 80 |
|
79 | 81 | $ooxml = $this->config->getAppValue(Application::APPNAME, 'doc_format', 'ooxml') === 'ooxml'; |
80 | 82 | $format = $ooxml ? 'pptx' : 'odp'; |
81 | 83 |
|
82 | 84 | try { |
83 | | - [$presentationStyle, $parsedStructure] = $this->parseModelJSON($rawModelOutput); |
| 85 | + [$presentationStyle, $parsedStructure] = $this->parseModelJSON($rawModelOutput, $includeWatermark); |
84 | 86 | } catch (\JsonException) { |
85 | 87 | throw new RuntimeException('LLM generated faulty JSON data'); |
86 | 88 | } |
@@ -108,7 +110,7 @@ public function generateSlideDeck(?string $userId, string $presentationText) { |
108 | 110 | * @param string $jsonString |
109 | 111 | * @return array |
110 | 112 | */ |
111 | | - private function parseModelJSON(string $jsonString): array { |
| 113 | + private function parseModelJSON(string $jsonString, bool $includeWatermark = true): array { |
112 | 114 | $jsonString = trim($jsonString, "` \n\r\t\v\0"); |
113 | 115 | $modelJSON = json_decode( |
114 | 116 | $jsonString, |
@@ -148,9 +150,19 @@ private function parseModelJSON(string $jsonString): array { |
148 | 150 | $presentation->addSlide($slide); |
149 | 151 | } |
150 | 152 |
|
| 153 | + if ($includeWatermark) { |
| 154 | + // Add a final slide with a note that this was generated by AI |
| 155 | + $this->addAiComment(isset($index) ? $index + 1 : 0, $presentation); |
| 156 | + } |
| 157 | + |
151 | 158 | return [$presentation->getStyle(), $presentation->getSlideCommands()]; |
152 | 159 | } |
153 | 160 |
|
| 161 | + private function addAiComment(int $index, Presentation $presentation) : void { |
| 162 | + $slide = new TitleContentSlide($index, '', $this->l10n->t('Generated using Artificial Intelligence')); |
| 163 | + $presentation->addSlide($slide); |
| 164 | + } |
| 165 | + |
154 | 166 | /** |
155 | 167 | * Creates a presentation file in memory |
156 | 168 | * |
|
0 commit comments