Skip to content

Commit b6ca768

Browse files
authored
Merge pull request #12063 from nextcloud/docs/taskprocessing-enums-defaults
docs(TaskProcessing): Update docs to reflect latest changes
2 parents 8801393 + 17fb341 commit b6ca768

File tree

9 files changed

+184
-19
lines changed

9 files changed

+184
-19
lines changed

admin_manual/ai/app_assistant.rst

+14
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,17 @@ This field is appended to the block of chat messages, i.e. attached after the me
160160
161161
The number of latest messages to consider for generating the next message. This does not include the user instructions, which is always considered in addition to this. This value should be adjusted in case you are hitting the token limit in your conversations too often.
162162
The AI text generation provider should ideally handle the max token limit case.
163+
164+
Improve AI processing throughput
165+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166+
167+
Most AI tasks will be run as part of the background job system in Nextcloud which only runs jobs every 5 minutes by default.
168+
To pick up scheduled jobs faster you can set up background job workers that process AI tasks as soon as they are scheduled:
169+
170+
run the following occ commands a daemon (you can also spawn multiple, for parallel processing):
171+
172+
.. code-block::
173+
174+
occ background-job:worker 'OC\TaskProcessing\SynchronousBackgroundJob'
175+
176+
Make sure to restart these daemons regularly, for example once a day, to make sure the daemon runs the latest code.

admin_manual/ai/app_context_chat.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ Installation
5757
Initial loading of data
5858
-----------------------
5959

60-
Context chat will automatically load user data into the Vector DB using background jobs. To speed this up, you can set up multiple background job worker machines and run the following occ commands in parallel on each:
60+
Context chat will automatically load user data into the Vector DB using background jobs. To speed this up, you can set up multiple background job workers (possibly on dedicated machines) and run the following occ commands as daemons in parallel on each:
6161

6262
.. code-block::
6363
64-
occ background-job:worker OCA\ContextChat\BackgroundJobs\StorageCrawlJob
64+
occ background-job:worker 'OCA\ContextChat\BackgroundJobs\StorageCrawlJob'
6565
6666
.. code-block::
6767
68-
occ background-job:worker OCA\ContextChat\BackgroundJobs\IndexerJob
68+
occ background-job:worker 'OCA\ContextChat\BackgroundJobs\IndexerJob'
6969
7070
This will ensure that the necessary background jobs are run as often as possible: ``StorageCrawlJob`` will crawl Nextcloud storages and put files that it finds into a queue and ``IndexerJob`` will iterate over the queue and load the file content into the Vector DB.
7171

72+
Make sure to restart these daemons regularly. For example once a day.
73+
7274
Scaling
7375
-------
7476

admin_manual/configuration_server/config_sample_php_parameters.rst

+8-11
Original file line numberDiff line numberDiff line change
@@ -1946,13 +1946,10 @@ preview_imaginary_url
19461946

19471947
Set the URL of the Imaginary service to send image previews to.
19481948

1949-
Also requires the
1950-
- ``OC\Preview\Imaginary``
1951-
provider to be enabled in the 'enabledPreviewProviders' array, to create previews for these mimetypes:
1952-
bmp, x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff, webp and illustrator.
1953-
If you want Imaginary to also create preview images from PDF Documents, you have to add
1954-
- ``OC\Preview\ImaginaryPDF``
1955-
provider as well.
1949+
Also requires the ``OC\Preview\Imaginary``
1950+
provider to be enabled in the 'enabledPreviewProviders' array to create previews for these mimetypes: bmp, x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff, webp and illustrator.
1951+
1952+
If you want Imaginary to also create preview images from PDF Documents, you have to add ``OC\Preview\ImaginaryPDF`` provider as well.
19561953

19571954
See https://github.com/h2non/imaginary
19581955

@@ -2317,16 +2314,16 @@ memcached_options
23172314
\Memcached::OPT_SEND_TIMEOUT => 50,
23182315
\Memcached::OPT_RECV_TIMEOUT => 50,
23192316
\Memcached::OPT_POLL_TIMEOUT => 50,
2320-
2317+
23212318
// Enable compression
23222319
\Memcached::OPT_COMPRESSION => true,
2323-
2320+
23242321
// Turn on consistent hashing
23252322
\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
2326-
2323+
23272324
// Enable Binary Protocol
23282325
\Memcached::OPT_BINARY_PROTOCOL => true,
2329-
2326+
23302327
// Binary serializer vill be enabled if the igbinary PECL module is available
23312328
//\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_IGBINARY,
23322329
],

developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_30.rst

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ Added APIs
126126
- ``OCP\App\IAppManager::BACKEND_CALDAV`` was added to represent the caldav backend dependency for ``isBackendRequired()``.
127127
- ``OCP\App\IAppManager::isBackendRequired()`` was added to check if at least one app requires a specific backend (currently only ``caldav``).
128128
- ``OCP\Accounts\IAccountManager::PROPERTY_BIRTHDATE`` was added to allow users to configure their date of birth in their profiles.
129+
- ``OCP\TaskProcessing``` was added to unify task processing of AI tasks and other types of tasks. See :ref:`Task Processing<task_processing>`
130+
- ``OCP\AppFramework\Bootstrap\IRegistrationContext::registerTaskProcessingProvider()`` was added to allow registering task processing providers
131+
- ``OCP\AppFramework\Bootstrap\IRegistrationContext::registerTaskProcessingTaskType()`` was added to allow registering task processing task types
132+
- ``OCP\Files\IRootFolder::getAppDataDirectoryName()`` was added to allow getting the name of the app data directory
129133

130134
Changed APIs
131135
^^^^^^^^^^^^
@@ -175,6 +179,10 @@ Deprecated APIs
175179
- Calling ``OCP\DB\QueryBuilder\IQueryBuilder::update()`` with ``$alias`` is deprecated and will throw an exception in a future version as the underlying library is removing the functionality.
176180
- Calling ``OCP\IDBConnection::getDatabasePlatform()`` is deprecated and will throw an exception in a future version as the underlying library is renaming and removing platforms which breaks the backwards-compatibility. Use ``getDatabaseProvider()`` instead.
177181
- Calling ``OCP\Files\Lock\ILockManager::registerLockProvider()`` is deprecated and will be removed in the future. Use ``registerLazyLockProvider()`` instead.
182+
- Using ``OCP\Translation`` is deprecated and will be removed in the future. Use ``OCP\TaskProcessing`` instead.
183+
- Using ``OCP\SpeechToText`` is deprecated and will be removed in the future. Use ``OCP\TaskProcessing`` instead. Existing ``SpeechToText`` providers will continue to work with the TaskProcessing API until then.
184+
- Using ``OCP\TextToImage`` is deprecated and will be removed in the future. Use ``OCP\TaskProcessing`` instead. Existing ``TextToImage`` providers will continue to work with the TaskProcessing API until then.
185+
- Using ``OCP\TextProcessing`` is deprecated and will be removed in the future. Use ``OCP\TaskProcessing`` instead. Existing ``TextProcessing`` providers will continue to work with the TaskProcessing API until then.
178186

179187
Removed APIs
180188
^^^^^^^^^^^^

developer_manual/digging_deeper/speech-to-text.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Speech-To-Text
66

77
.. versionadded:: 27
88

9+
.. deprecated:: 30
10+
Use the TaskProcessing API instead
11+
912
Nextcloud offers a **Speech-To-Text** API. The overall idea is that there is a central OCP API that apps can use to request transcriptions of audio or video files. To be technology agnostic any app can provide this Speech-To-Text functionality by registering a Speech-To-Text provider.
1013

1114
Consuming the Speech-To-Text API
@@ -182,4 +185,4 @@ The provider class is registered via the :ref:`bootstrap mechanism<Bootstrapping
182185
183186
public function boot(IBootContext $context): void {}
184187
185-
}
188+
}

developer_manual/digging_deeper/task_processing.rst

+134-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ The following built-in task types are available:
6868
* ``input``: ``Text``
6969
* Output shape:
7070
* ``output``: ``Text``
71+
* ``'core:text2text:translate'``: This task will translate text from one language to another. It is implemented by ``\OCP\TaskProcessing\TaskTypes\TextToTextTranslate``
72+
* Input shape:
73+
* ``input``: ``Text``
74+
* ``origin_language``: ``Enum``
75+
* ``target_language``: ``Enum``
76+
* Output shape:
77+
* ``output``: ``Text``
7178
* ``'core:audio2text'``: This task type is for transcribing audio to text. It is implemented by ``\OCP\TaskProcessing\TaskTypes\AudioToText``
7279
* Input shape:
7380
* ``input``: ``Audio``
@@ -126,6 +133,7 @@ Input and output shape keys can have one of a pre-defined set of types, which ar
126133
case Audio = 3;
127134
case Video = 4;
128135
case File = 5;
136+
case Enum = 6;
129137
case ListOfNumbers = 10;
130138
case ListOfTexts = 11;
131139
case ListOfImages = 12;
@@ -158,6 +166,17 @@ The task class objects have the following methods available:
158166
* ``getAppId()`` This returns the originating application ID of the task.
159167
* ``getCustomId()`` This returns the original scheduler-defined identifier for the task
160168
* ``getUserId()`` This returns the originating user ID of the task.
169+
* ``getCompletionExpectedAt()`` This is available after scheduling the task and returns the DateTime when the task is expected to be completed
170+
* ``getLastUpdated()`` This returns the time the task was last updated as a unix timestamp
171+
* ``getScheduledAt()`` This returns the time the task was scheduled as a unix timestamp
172+
* ``getStartedAt()`` This returns the time the task execution started as a unix timestamp
173+
* ``getEndedAt()`` This returns the time the task execution ended as a unix timestamp
174+
* ``getErrorMessage()`` This returns the error message if the task execution failed
175+
* ``getProgress()`` This returns the current task progress, between 0 and 1 while the task is running. Will be 1 when the task is completed
176+
* ``setWebhookUri()`` This sets the URI of a webhook that will be notified when the task execution has ended
177+
* ``setWebhookMethod()`` This sets the HTTP method that will be used for the webhook when the task execution has ended
178+
* ``getWebhookUri()`` This returns the webhook URI that will be notified when the task execution has ended
179+
* ``getWebhookMethod()`` This returns the HTTP method that will be used for the webhook when the task execution has ended
161180

162181
You could now schedule the task as follows:
163182

@@ -261,7 +280,7 @@ A **Task processing provider** will usually be a class that implements the inter
261280
) {
262281
}
263282
264-
public function getId() {
283+
public function getId(): string {
265284
return 'myapp:summary';
266285
}
267286
@@ -277,17 +296,129 @@ A **Task processing provider** will usually be a class that implements the inter
277296
// Return the output here
278297
}
279298
280-
public function getExpectedRuntime() {
299+
public function getExpectedRuntime(): int {
281300
// usually takes 1min on average
282301
return 60;
283302
}
303+
304+
public function getInputShapeDefaults(): array {
305+
return [];
306+
}
307+
308+
public function getOptionalInputShape(): array {
309+
return [];
310+
}
311+
312+
public function getOptionalInputShapeDefaults(): array {
313+
return [];
314+
}
315+
316+
public function getOptionalOutputShape(): array {
317+
return [];
318+
}
319+
320+
public function getInputShapeEnumValues(): array {
321+
return [];
322+
}
323+
324+
public function getOptionalInputShapeEnumValues(): array {
325+
return [];
326+
}
327+
328+
public function getOutputShapeEnumValues(): array {
329+
return [];
330+
}
331+
332+
public function getOptionalOutputShapeEnumValues(): array {
333+
return [];
334+
}
284335
}
285336
286337
The method ``getName`` returns a string to identify the registered provider in the user interface.
287338

288339
The method ``process`` implements the text processing step. In case execution fails for some reason, you should throw a ``\OCP\TaskProcessing\Exception\ProcessingException`` with an explanatory error message. Important to note here is that ``Image``, ``Audio``, ``Video`` and ``File`` slots in the input array will be filled with ``\OCP\Files\File`` objects for your convenience. When outputting one of these you should simply return a string, the API will turn the data into a proper file for convenience. The ``$reportProgress`` parameter is a callback that you may use at will to report the task progress as a single float value between 0 and 1. Its return value will indicate if the task is still running (``true``) or if it was cancelled (``false``) and processing should be terminated.
289340

290-
This class would typically be saved into a file in ``lib/TextProcessing`` 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>`.
341+
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>`.
342+
343+
Providing additional inputs and outputs
344+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
345+
346+
Built-in task types often only specify the most basic input and output slots. If you would like to offer more input options
347+
with your provider you can specify optional inputs and outputs using the ``getOptionalInputShape`` and ``getOptionalOutputShape`` methods.
348+
You will need to return an associative array of ``\OCP\TaskProcessing\ShapeDescriptor`` objects.
349+
350+
.. code-block:: php
351+
352+
public function getOptionalInputShape(): array {
353+
return [
354+
'tone' => new ShapeDescriptor($this->l->t('Tone of voice'), $this->l->t('Set the tone of voice to be used for the output'), EShapeType::Text)
355+
];
356+
}
357+
358+
In the same vein you can also provide optional output shape slots in addition to the pre-defined output slots.
359+
360+
.. code-block:: php
361+
362+
public function getOptionalOutputShape(): array {
363+
return [
364+
'co2_emissions' => new ShapeDescriptor($this->l->t('CO2 Emissions'), $this->l->t('The CO2 emissions produced by running this task in metric tons'), EShapeType::Number)
365+
];
366+
}
367+
368+
Providing input defaults
369+
^^^^^^^^^^^^^^^^^^^^^^^^
370+
371+
With the method ``getInputShapeDefaults`` you can specify default values for input slots (which are defined by the task type). For example:
372+
373+
.. code-block:: php
374+
375+
public function getInputShapeDefaults(): array {
376+
return [
377+
'input' => 'There was once a man with many cows who wanted to have even more cows.'
378+
];
379+
}
380+
381+
Note that you can only specify default values for 'Text' and 'Number' slots.
382+
383+
The same works for your optional input shapes that you defined in ``getOptionalInputShape``:
384+
385+
.. code-block:: php
386+
387+
public function getOptionalInputShapeDefaults(): array {
388+
return [
389+
'tone' => 'Formal'
390+
];
391+
}
392+
393+
Working with Enum shape types
394+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
395+
396+
Both input and output shapes as well as the optional input and output shapes allow declaring slots of type ``'Enum'``. An Enum
397+
is a type that only allows values from a pre-defined set. In the case of the TaskProcessing API this set is not defined by the task type, but
398+
by the provider implementing the task type using ``getInputShapeEnumValues``, ``getOutputShapeEnumValues``, ``getOptionalInputShapeEnumValues`` and ``getOptionalOutputShapeEnumValues``.
399+
400+
You could, for example, implement the above tone of voice slot using an Enum:
401+
402+
.. code-block:: php
403+
404+
public function getOptionalInputShape(): array {
405+
return [
406+
'tone' => new ShapeDescriptor($this->l->t('Tone of voice'), $this->l->t('Set the tone of voice to be used for the output'), EShapeType::Enum)
407+
];
408+
}
409+
410+
.. code-block:: php
411+
412+
public function getOptionalInputShapeEnumValues(): array {
413+
return [
414+
'tone' => [
415+
new ShapeEnumValue($this->l->t('Simple'), 'So that a kid could understand'),
416+
new ShapeEnumValue($this->l->t('Funny'), 'Funny'),
417+
new ShapeEnumValue($this->l->t('Formal'), 'Formal'),
418+
]
419+
];
420+
}
421+
291422
292423
Providing more task types
293424
^^^^^^^^^^^^^^^^^^^^^^^^^

developer_manual/digging_deeper/text2image.rst

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Text-To-Image
66

77
.. versionadded:: 28
88

9+
.. deprecated:: 30
10+
Use the TaskProcessing API instead
11+
912
Nextcloud offers a **Text-To-Image** API. The overall idea is that there is a central OCP API that apps can use to prompt tasks to latent diffusion AI models and similar image generation tools. To be technology agnostic any app can provide this functionality by registering a Text-To-Image provider.
1013

1114
Consuming the Text-To-Image API

developer_manual/digging_deeper/text_processing.rst

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Text Processing
66

77
.. versionadded:: 27.1.0
88

9+
.. deprecated:: 30
10+
Use the TaskProcessing API instead
11+
12+
913
Nextcloud offers a **Text Processing** API. The overall idea is that there is a central OCP API that apps can use to prompt tasks to Large Language Models and similar text processing tools. To be technology agnostic any app can provide this functionality by registering Text Processing providers.
1014

1115
Consuming the Text Processing API

developer_manual/digging_deeper/translation.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Machine Translation
66

77
.. versionadded:: 26
88

9+
.. deprecated:: 30
10+
Use the TaskProcessing API instead
11+
912
Nextcloud offers a **Translation** API. The overall idea is that there is a central OCP API that apps can use to request machine translations of text. To be technology agnostic any app can provide this Translation functionality by registering a Translation provider.
1013

1114
Consuming the Translation API
@@ -187,4 +190,4 @@ The provider class is registered via the :ref:`bootstrap mechanism<Bootstrapping
187190
188191
public function boot(IBootContext $context): void {}
189192
190-
}
193+
}

0 commit comments

Comments
 (0)