Skip to content

Commit 26ab76c

Browse files
committed
docs(task-processing): document a new interface, inform about API changes in the release notes
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 5cb9b03 commit 26ab76c

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

developer_manual/digging_deeper/task_processing.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ A **Task processing provider** will usually be a class that implements the inter
347347
use OCP\TaskProcessing\SummaryTaskType;
348348
use OCP\IL10N;
349349
350-
class Provider implements ISynchrounousProvider {
350+
class Provider implements ISynchronousProvider {
351351
352352
public function __construct(
353353
private IL10N $l,
@@ -417,6 +417,43 @@ Important to note here is that ``Image``, ``Audio``, ``Video`` and ``File`` slot
417417

418418
This class would typically be saved into a file in ``lib/TaskProcessing`` of your app but you are free to put it elsewhere as long as it's loadable by Nextcloud's :ref:`dependency injection container<dependency-injection>`.
419419

420+
Implementing an advanced TaskProcessing provider
421+
------------------------------------------------
422+
423+
The ``\OCP\TaskProcessing\ISynchronousOptionsAwareProvider`` interface is available if you want your provider
424+
to support watermarking or streaming. If your provider implements ``\OCP\TaskProcessing\ISynchronousOptionsAwareProvider``,
425+
the process method should be adjusted:
426+
427+
.. code-block:: php
428+
429+
public function process(
430+
?string $userId, array $input, callable $reportProgress,
431+
SynchronousProviderOptions $options = new SynchronousProviderOptions(),
432+
): array {
433+
$includeWatermark = $options->getIncludeWatermark();
434+
$preferStreaming = $options->getPreferStreaming();
435+
$reportOutput = $options->getReportIntermediateOutput();
436+
437+
$textOutput = '1';
438+
if ($preferStreaming) {
439+
$reportOutput(['output' => $textOutput]);
440+
}
441+
foreach (range(2, 100) as $i) {
442+
$textOutput .= ' and ' . $i;
443+
$reportProgress($i / 100);
444+
if ($preferStreaming) {
445+
$reportOutput(['output' => $textOutput]);
446+
}
447+
}
448+
449+
if ($includeWatermark) {
450+
$textOutput .= "\n" . 'This was generated using artificial intelligence.';
451+
}
452+
453+
return ['output' => $textOutput];
454+
}
455+
456+
420457
Providing additional inputs and outputs
421458
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
422459

developer_manual/release_notes/new.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ but they might be required to have a fully working instance later on.
3434
Expensive repair steps are only executed when explicitly requested by the administrator.
3535

3636
See :ref:`migration-repair-steps` for details.
37+
38+
Added APIs
39+
^^^^^^^^^^
40+
41+
- There is a new TaskProcessing provider interface: ``\OCP\TaskProcessing\ISynchronousOptionsAwareProvider``. It takes a ``\OCP\TaskProcessing\SynchronousProviderOptions`` option object that contains includeWatermarks, preferStreaming and the callback to report intermediate output.
42+
43+
Changed APIs
44+
^^^^^^^^^^^^
45+
46+
- The ``\OCP\TaskProcessing\Task`` class now has ``getPreferStreaming`` and ``setPreferStreaming`` methods for indicating whether the provider should report the output progressively if it supports it.
47+
- The TaskProcessing OCS API now also accepts the ``preferStreaming`` flag when scheduling tasks.
48+
49+
Deprecated APIs
50+
^^^^^^^^^^^^^^^
51+
52+
- ``\OCP\TaskProcessing\ISynchronousWatermarkingProvider`` is now deprecated. ``\OCP\TaskProcessing\ISynchronousOptionsAwareProvider`` should now be used instead.

0 commit comments

Comments
 (0)