aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2024-12-06 12:09:18 +0100
committerMarcel Klehr <mklehr@gmx.net>2024-12-09 14:10:59 +0100
commite5ce55551d51ae40ea534eccbc1f618a0c382fff (patch)
tree2e5bd2210e436bf89207c21250d7dbe18d1b43c7
parent6f3ee6b09a27cedf49c56b981d6d21fd852b4838 (diff)
downloadnextcloud-server-e5ce55551d51ae40ea534eccbc1f618a0c382fff.tar.gz
nextcloud-server-e5ce55551d51ae40ea534eccbc1f618a0c382fff.zip
feat(TaskProcessing): More task types
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
-rw-r--r--lib/composer/composer/autoload_classmap.php3
-rw-r--r--lib/composer/composer/autoload_static.php3
-rw-r--r--lib/private/TaskProcessing/Manager.php3
-rw-r--r--lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php108
-rw-r--r--lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php93
-rw-r--r--lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php114
6 files changed, 324 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 746e43248d8..e515e3eff07 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -810,11 +810,14 @@ return array(
'OCP\\TaskProcessing\\ShapeEnumValue' => $baseDir . '/lib/public/TaskProcessing/ShapeEnumValue.php',
'OCP\\TaskProcessing\\Task' => $baseDir . '/lib/public/TaskProcessing/Task.php',
'OCP\\TaskProcessing\\TaskTypes\\AudioToText' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/AudioToText.php',
+ 'OCP\\TaskProcessing\\TaskTypes\\ContextAgentInteraction' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php',
'OCP\\TaskProcessing\\TaskTypes\\ContextWrite' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/ContextWrite.php',
'OCP\\TaskProcessing\\TaskTypes\\GenerateEmoji' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/GenerateEmoji.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToImage' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToImage.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToText' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToText.php',
+ 'OCP\\TaskProcessing\\TaskTypes\\TextToTextChangeTone' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextChat' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToTextChat.php',
+ 'OCP\\TaskProcessing\\TaskTypes\\TextToTextChatWithTools' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextFormalization' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToTextFormalization.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextHeadline' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToTextHeadline.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextReformulation' => $baseDir . '/lib/public/TaskProcessing/TaskTypes/TextToTextReformulation.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 62124d74496..cf2883c3070 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -851,11 +851,14 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\TaskProcessing\\ShapeEnumValue' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ShapeEnumValue.php',
'OCP\\TaskProcessing\\Task' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/Task.php',
'OCP\\TaskProcessing\\TaskTypes\\AudioToText' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/AudioToText.php',
+ 'OCP\\TaskProcessing\\TaskTypes\\ContextAgentInteraction' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php',
'OCP\\TaskProcessing\\TaskTypes\\ContextWrite' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/ContextWrite.php',
'OCP\\TaskProcessing\\TaskTypes\\GenerateEmoji' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/GenerateEmoji.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToImage' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToImage.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToText' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToText.php',
+ 'OCP\\TaskProcessing\\TaskTypes\\TextToTextChangeTone' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextChat' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToTextChat.php',
+ 'OCP\\TaskProcessing\\TaskTypes\\TextToTextChatWithTools' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextFormalization' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToTextFormalization.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextHeadline' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToTextHeadline.php',
'OCP\\TaskProcessing\\TaskTypes\\TextToTextReformulation' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/TaskTypes/TextToTextReformulation.php',
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php
index 4e9668021ad..ffa39912a01 100644
--- a/lib/private/TaskProcessing/Manager.php
+++ b/lib/private/TaskProcessing/Manager.php
@@ -538,6 +538,9 @@ class Manager implements IManager {
\OCP\TaskProcessing\TaskTypes\AudioToText::ID => \OCP\Server::get(\OCP\TaskProcessing\TaskTypes\AudioToText::class),
\OCP\TaskProcessing\TaskTypes\ContextWrite::ID => \OCP\Server::get(\OCP\TaskProcessing\TaskTypes\ContextWrite::class),
\OCP\TaskProcessing\TaskTypes\GenerateEmoji::ID => \OCP\Server::get(\OCP\TaskProcessing\TaskTypes\GenerateEmoji::class),
+ \OCP\TaskProcessing\TaskTypes\TextToTextChangeTone::ID => \OCP\Server::get(\OCP\TaskProcessing\TaskTypes\TextToTextChangeTone::class),
+ \OCP\TaskProcessing\TaskTypes\TextToTextChatWithTools::ID => \OCP\Server::get(\OCP\TaskProcessing\TaskTypes\TextToTextChatWithTools::class),
+ \OCP\TaskProcessing\TaskTypes\ContextAgentInteraction::ID => \OCP\Server::get(\OCP\TaskProcessing\TaskTypes\ContextAgentInteraction::class),
];
foreach ($context->getTaskProcessingTaskTypes() as $providerServiceRegistration) {
diff --git a/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php b/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php
new file mode 100644
index 00000000000..f5bef6b48e3
--- /dev/null
+++ b/lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php
@@ -0,0 +1,108 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\TaskProcessing\TaskTypes;
+
+use OCP\IL10N;
+use OCP\L10N\IFactory;
+use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\ITaskType;
+use OCP\TaskProcessing\ShapeDescriptor;
+
+/**
+ * This is the task processing task type for Context Agent interaction
+ * @since 31.0.0
+ */
+class ContextAgentInteraction implements ITaskType {
+ public const ID = 'core:contextagent:interaction';
+
+ private IL10N $l;
+
+ /**
+ * @param IFactory $l10nFactory
+ * @since 31.0.0
+ */
+ public function __construct(
+ IFactory $l10nFactory,
+ ) {
+ $this->l = $l10nFactory->get('core');
+ }
+
+ /**
+ * @inheritDoc
+ * @since 31.0.0
+ */
+ public function getName(): string {
+ return $this->l->t('ContextAgent');
+ }
+
+ /**
+ * @inheritDoc
+ * @since 31.0.0
+ */
+ public function getDescription(): string {
+ return $this->l->t('Chat with an agent');
+ }
+
+ /**
+ * @return string
+ * @since 31.0.0
+ */
+ public function getId(): string {
+ return self::ID;
+ }
+
+ /**
+ * @return ShapeDescriptor[]
+ * @since 31.0.0
+ */
+ public function getInputShape(): array {
+ return [
+ 'input' => new ShapeDescriptor(
+ $this->l->t('Chat message'),
+ $this->l->t('A chat message to send to the agent.'),
+ EShapeType::Text
+ ),
+ 'confirmation' => new ShapeDescriptor(
+ $this->l->t('Confirmation'),
+ $this->l->t('Whether to confirm previously requested actions: 0 for denial and 1 for confirmation.'),
+ EShapeType::Number
+ ),
+ 'conversation_token' => new ShapeDescriptor(
+ $this->l->t('Conversation token'),
+ $this->l->t('A token representing the conversation.'),
+ EShapeType::Text
+ ),
+ ];
+ }
+
+ /**
+ * @return ShapeDescriptor[]
+ * @since 31.0.0
+ */
+ public function getOutputShape(): array {
+ return [
+ 'output' => new ShapeDescriptor(
+ $this->l->t('Generated response'),
+ $this->l->t('The response from the chat model.'),
+ EShapeType::Text
+ ),
+ 'conversation_token' => new ShapeDescriptor(
+ $this->l->t('The new conversation token'),
+ $this->l->t('Send this along with the next interaction.'),
+ EShapeType::Text
+ ),
+ 'actions' => new ShapeDescriptor(
+ $this->l->t('Requested actions by the agent'),
+ $this->l->t('Actions that the agent would like to carry out in JSON format.'),
+ EShapeType::Text
+ ),
+ ];
+ }
+}
diff --git a/lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php b/lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php
new file mode 100644
index 00000000000..bab60976454
--- /dev/null
+++ b/lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php
@@ -0,0 +1,93 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\TaskProcessing\TaskTypes;
+
+use OCP\IL10N;
+use OCP\L10N\IFactory;
+use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\ITaskType;
+use OCP\TaskProcessing\ShapeDescriptor;
+
+/**
+ * This is the task processing task type for text reformulation
+ * @since 31.0.0
+ */
+class TextToTextChangeTone implements ITaskType {
+ public const ID = 'core:text2text:changetone';
+
+ private IL10N $l;
+
+ /**
+ * @param IFactory $l10nFactory
+ * @since 31.0.0
+ */
+ public function __construct(
+ IFactory $l10nFactory,
+ ) {
+ $this->l = $l10nFactory->get('core');
+ }
+
+ /**
+ * @inheritDoc
+ * @since 31.0.0
+ */
+ public function getName(): string {
+ return $this->l->t('Change Tone');
+ }
+
+ /**
+ * @inheritDoc
+ * @since 31.0.0
+ */
+ public function getDescription(): string {
+ return $this->l->t('Change the tone of a piece of text.');
+ }
+
+ /**
+ * @return string
+ * @since 31.0.0
+ */
+ public function getId(): string {
+ return self::ID;
+ }
+
+ /**
+ * @return ShapeDescriptor[]
+ * @since 31.0.0
+ */
+ public function getInputShape(): array {
+ return [
+ 'input' => new ShapeDescriptor(
+ $this->l->t('Input text'),
+ $this->l->t('Write a text that you want the assistant to rewrite in another tone.'),
+ EShapeType::Text,
+ ),
+ 'tone' => new ShapeDescriptor(
+ $this->l->t('Desired tone'),
+ $this->l->t('In which tone should your text be rewritten?'),
+ EShapeType::Enum,
+ ),
+ ];
+ }
+
+ /**
+ * @return ShapeDescriptor[]
+ * @since 31.0.0
+ */
+ public function getOutputShape(): array {
+ return [
+ 'output' => new ShapeDescriptor(
+ $this->l->t('Generated response'),
+ $this->l->t('The rewritten text in the desired tone, written by the assistant:'),
+ EShapeType::Text
+ ),
+ ];
+ }
+}
diff --git a/lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php b/lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php
new file mode 100644
index 00000000000..b992f33e132
--- /dev/null
+++ b/lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php
@@ -0,0 +1,114 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\TaskProcessing\TaskTypes;
+
+use OCP\IL10N;
+use OCP\L10N\IFactory;
+use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\ITaskType;
+use OCP\TaskProcessing\ShapeDescriptor;
+
+/**
+ * This is the task processing task type for invoking Chat-enabled LLMs with tool call support
+ * @since 31.0.0
+ */
+class TextToTextChatWithTools implements ITaskType {
+ public const ID = 'core:text2text:chatwithtools';
+
+ private IL10N $l;
+
+ /**
+ * @param IFactory $l10nFactory
+ * @since 31.0.0
+ */
+ public function __construct(
+ IFactory $l10nFactory,
+ ) {
+ $this->l = $l10nFactory->get('core');
+ }
+
+ /**
+ * @inheritDoc
+ * @since 31.0.0
+ */
+ public function getName(): string {
+ return $this->l->t('Chat with tools');
+ }
+
+ /**
+ * @inheritDoc
+ * @since 31.0.0
+ */
+ public function getDescription(): string {
+ return $this->l->t('Chat with the language model with tool calling support.');
+ }
+
+ /**
+ * @return string
+ * @since 31.0.0
+ */
+ public function getId(): string {
+ return self::ID;
+ }
+
+ /**
+ * @return ShapeDescriptor[]
+ * @since 31.0.0
+ */
+ public function getInputShape(): array {
+ return [
+ 'system_prompt' => new ShapeDescriptor(
+ $this->l->t('System prompt'),
+ $this->l->t('Define rules and assumptions that the assistant should follow during the conversation.'),
+ EShapeType::Text
+ ),
+ 'input' => new ShapeDescriptor(
+ $this->l->t('Chat message'),
+ $this->l->t('Describe a task that you want the assistant to do or ask a question'),
+ EShapeType::Text
+ ),
+ 'tool_message' => new ShapeDescriptor(
+ $this->l->t('Tool message'),
+ $this->l->t('The result of tool calls in the last interaction'),
+ EShapeType::Text
+ ),
+ 'history' => new ShapeDescriptor(
+ $this->l->t('Chat history'),
+ $this->l->t('The history of chat messages before the current message, starting with a message by the user'),
+ EShapeType::ListOfTexts
+ ),
+ // See https://platform.openai.com/docs/api-reference/chat/create#chat-create-tools for the format
+ 'tools' => new ShapeDescriptor(
+ $this->l->t('Available tools'),
+ $this->l->t('The available tools in JSON format'),
+ EShapeType::Text
+ ),
+ ];
+ }
+
+ /**
+ * @return ShapeDescriptor[]
+ * @since 31.0.0
+ */
+ public function getOutputShape(): array {
+ return [
+ 'output' => new ShapeDescriptor(
+ $this->l->t('Generated response'),
+ $this->l->t('The response from the chat model'),
+ EShapeType::Text
+ ),
+ 'tool_calls' => new ShapeDescriptor(
+ $this->l->t('Tool calls'),
+ $this->l->t('Tools call instructions from the model in JSON format'),
+ EShapeType::Text
+ ),
+ ];
+ }
+}