-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TaskProcessing): More task types
Signed-off-by: Marcel Klehr <[email protected]>
- Loading branch information
1 parent
6f3ee6b
commit 871372a
Showing
6 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
Check failure on line 89 in lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
Check failure on line 89 in lib/public/TaskProcessing/TaskTypes/ContextAgentInteraction.php GitHub Actions / static-code-analysisInvalidDocblock
|
||
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 | ||
), | ||
]; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
lib/public/TaskProcessing/TaskTypes/TextToTextChangeTone.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
), | ||
]; | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
lib/public/TaskProcessing/TaskTypes/TextToTextChatWithTools.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
), | ||
]; | ||
} | ||
} |