|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCP\TaskProcessing\TaskTypes; |
| 11 | + |
| 12 | +use OCP\IL10N; |
| 13 | +use OCP\L10N\IFactory; |
| 14 | +use OCP\TaskProcessing\EShapeType; |
| 15 | +use OCP\TaskProcessing\IInternalTaskType; |
| 16 | +use OCP\TaskProcessing\ITaskType; |
| 17 | +use OCP\TaskProcessing\ShapeDescriptor; |
| 18 | + |
| 19 | +/** |
| 20 | + * This is the task processing task type for invoking multimodal Chat-enabled LLMs with tool call support |
| 21 | + * @since 35.0.0 |
| 22 | + */ |
| 23 | +class MultimodalChatWithTools implements ITaskType { |
| 24 | + /** |
| 25 | + * @since 35.0.0 |
| 26 | + */ |
| 27 | + public const ID = 'core:text2text:multimodal-chatwithtools'; |
| 28 | + |
| 29 | + private IL10N $l; |
| 30 | + |
| 31 | + /** |
| 32 | + * @param IFactory $l10nFactory |
| 33 | + * @since 35.0.0 |
| 34 | + */ |
| 35 | + public function __construct( |
| 36 | + IFactory $l10nFactory, |
| 37 | + ) { |
| 38 | + $this->l = $l10nFactory->get('lib'); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @inheritDoc |
| 43 | + * @since 35.0.0 |
| 44 | + */ |
| 45 | + #[\Override] |
| 46 | + public function getName(): string { |
| 47 | + // TRANSLATORS Tool calling, also known as function calling, is a structured way to give LLMs the ability to make requests back to the application that called it. You define the tools you want to make available to the model, and the model will make tool requests to your app as necessary to fulfill the prompts you give it. |
| 48 | + return $this->l->t('Chat with tools using attachments'); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @inheritDoc |
| 53 | + * @since 35.0.0 |
| 54 | + */ |
| 55 | + #[\Override] |
| 56 | + public function getDescription(): string { |
| 57 | + // TRANSLATORS Tool calling, also known as function calling, is a structured way to give LLMs the ability to make requests back to the application that called it. You define the tools you want to make available to the model, and the model will make tool requests to your app as necessary to fulfill the prompts you give it. |
| 58 | + return $this->l->t('Chat with the language model with tool calling support and attachments.'); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return string |
| 63 | + * @since 35.0.0 |
| 64 | + */ |
| 65 | + #[\Override] |
| 66 | + public function getId(): string { |
| 67 | + return self::ID; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @return ShapeDescriptor[] |
| 72 | + * @since 35.0.0 |
| 73 | + */ |
| 74 | + #[\Override] |
| 75 | + public function getInputShape(): array { |
| 76 | + return [ |
| 77 | + 'system_prompt' => new ShapeDescriptor( |
| 78 | + $this->l->t('System prompt'), |
| 79 | + $this->l->t('Define rules and assumptions that the assistant should follow during the conversation.'), |
| 80 | + EShapeType::Text |
| 81 | + ), |
| 82 | + 'input' => new ShapeDescriptor( |
| 83 | + $this->l->t('Chat message'), |
| 84 | + $this->l->t('Describe a task that you want the assistant to do or ask a question'), |
| 85 | + EShapeType::Text |
| 86 | + ), |
| 87 | + 'input_attachments' => new ShapeDescriptor( |
| 88 | + $this->l->t('Input attachments'), |
| 89 | + $this->l->t('Files to send along with the chat message.'), |
| 90 | + EShapeType::ListOfFiles |
| 91 | + ), |
| 92 | + 'tool_message' => new ShapeDescriptor( |
| 93 | + $this->l->t('Tool message'), |
| 94 | + $this->l->t('The result of tool calls in the last interaction'), |
| 95 | + EShapeType::Text |
| 96 | + ), |
| 97 | + 'history' => new ShapeDescriptor( |
| 98 | + $this->l->t('Chat history'), |
| 99 | + $this->l->t('The history of chat messages before the current message, starting with a message by the user'), |
| 100 | + EShapeType::ListOfTexts |
| 101 | + ), |
| 102 | + // See https://platform.openai.com/docs/api-reference/chat/create#chat-create-tools for the format |
| 103 | + 'tools' => new ShapeDescriptor( |
| 104 | + // TRANSLATORS Tool calling, also known as function calling, is a structured way to give LLMs the ability to make requests back to the application that called it. You define the tools you want to make available to the model, and the model will make tool requests to your app as necessary to fulfill the prompts you give it. |
| 105 | + $this->l->t('Available tools'), |
| 106 | + $this->l->t('The available tools in JSON format'), |
| 107 | + EShapeType::Text |
| 108 | + ), |
| 109 | + ]; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * @return ShapeDescriptor[] |
| 114 | + * @since 35.0.0 |
| 115 | + */ |
| 116 | + #[\Override] |
| 117 | + public function getOutputShape(): array { |
| 118 | + return [ |
| 119 | + 'output' => new ShapeDescriptor( |
| 120 | + $this->l->t('Generated response'), |
| 121 | + $this->l->t('The response from the chat model'), |
| 122 | + EShapeType::Text |
| 123 | + ), |
| 124 | + 'output_attachments' => new ShapeDescriptor( |
| 125 | + $this->l->t('Output attachments'), |
| 126 | + $this->l->t('Files generated by the model.'), |
| 127 | + EShapeType::ListOfFiles |
| 128 | + ), |
| 129 | + 'tool_calls' => new ShapeDescriptor( |
| 130 | + $this->l->t('Tool calls'), |
| 131 | + $this->l->t('Tools call instructions from the model in JSON format'), |
| 132 | + EShapeType::Text |
| 133 | + ), |
| 134 | + ]; |
| 135 | + } |
| 136 | +} |
0 commit comments