Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* outputShape: array<string, AssistantShapeDescriptor>,
* optionalOutputShape: array<string, AssistantShapeDescriptor>,
* priority: integer,
* category: array{id: string, name: string},
* }
*
* @psalm-type AssistantTaskProcessingTask = array{
Expand Down
43 changes: 42 additions & 1 deletion lib/Service/AssistantService.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

Expand Down Expand Up @@ -232,6 +232,44 @@ public function isAudioChatAvailable(): bool {
&& array_key_exists(TextToTextChat::ID, $availableTaskTypes);
}

/**
* Get category information for a task type
*
* @param string $typeId The task type ID
* @return array{id: string, name: string}
*/
private function getCategory(string $typeId): array {
$categoryId = 'other';
$categoryName = $this->l10n->t('Other');
if (str_starts_with($typeId, 'chatty')) {
$categoryId = 'chat';
$categoryName = $this->l10n->t('Chat with AI');
} elseif (str_starts_with($typeId, 'context_chat')) {
$categoryId = 'context';
$categoryName = $this->l10n->t('Context Chat');
} elseif (str_contains($typeId, 'translate')) {
$categoryId = 'translate';
$categoryName = $this->l10n->t('Translate');
} elseif (str_starts_with($typeId, 'richdocuments')) {
$categoryId = 'generate';
$categoryName = $this->l10n->t('Generate file');
} elseif (str_contains($typeId, 'image') || str_contains($typeId, 'sticker')) {
$categoryId = 'image';
$categoryName = $this->l10n->t('Work with images');
} elseif (str_contains($typeId, 'audio') || str_contains($typeId, 'speech')) {
$categoryId = 'audio';
$categoryName = $this->l10n->t('Work with audio');
} elseif (str_contains($typeId, 'text')) {
$categoryId = 'text';
$categoryName = $this->l10n->t('Work with text');
}

return [
'id' => $categoryId,
'name' => $categoryName,
];
}

/**
* @return array<AssistantTaskProcessingTaskType>
*/
Expand All @@ -245,6 +283,7 @@ public function getAvailableTaskTypes(): array {
'description' => 'plop',
'id' => 'core:inputList',
'priority' => 0,
'category' => $this->getCategory('core:inputList'),
'inputShape' => [
'textList' => new ShapeDescriptor(
'Input text list',
Expand Down Expand Up @@ -333,6 +372,7 @@ public function getAvailableTaskTypes(): array {
'id' => 'chatty-llm',
'name' => $this->l10n->t('Chat with AI'),
'description' => $this->l10n->t('Chat with an AI model.'),
'category' => $this->getCategory('chatty-llm'),
'inputShape' => [],
'inputShapeEnumValues' => [],
'inputShapeDefaults' => [],
Expand All @@ -350,6 +390,7 @@ public function getAvailableTaskTypes(): array {
}
$taskTypeArray['id'] = $typeId;
$taskTypeArray['priority'] = self::TASK_TYPE_PRIORITIES[$typeId] ?? 1000;
$taskTypeArray['category'] = $this->getCategory($typeId);

if ($typeId === TextToText::ID) {
$taskTypeArray['name'] = $this->l10n->t('Generate text');
Expand Down
18 changes: 17 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@
"optionalInputShape",
"outputShape",
"optionalOutputShape",
"priority"
"priority",
"category"
],
"properties": {
"id": {
Expand Down Expand Up @@ -471,6 +472,21 @@
"priority": {
"type": "integer",
"format": "int64"
},
"category": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
Expand Down
50 changes: 8 additions & 42 deletions src/components/TaskTypeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default {
buttonTypes() {
const taskTypes = {}
for (const task of this.options) {
const type = this.getTaskCategory(task.id)
const type = task.category.id
if (!taskTypes[type]) {
taskTypes[type] = []
}
Expand All @@ -153,7 +153,7 @@ export default {
}
result.push({
id: entry[0],
text: this.getTextForCategory(entry[0]),
text: entry[1][0].category.name,
icon: this.getCategoryIcon(entry[0]),
tasks: entry[1],
})
Expand All @@ -162,7 +162,7 @@ export default {
if (taskTypes.other) {
result.push({
id: 'other',
text: this.getTextForCategory('other'),
text: taskTypes.other[0].category.name,
icon: this.getCategoryIcon('other'),
tasks: taskTypes.other,
})
Expand Down Expand Up @@ -201,7 +201,11 @@ export default {
return taskType.id === this.modelValue
},
isCategorySelected(category) {
return category.id === this.getTaskCategory(this.modelValue || '')
if (!this.modelValue) {
return false
}
const selectedTask = this.options.find(task => task.id === this.modelValue)
return selectedTask && category.id === selectedTask.category.id
},
onTaskSelected(taskType) {
this.$emit('update:model-value', taskType.id)
Expand All @@ -217,44 +221,6 @@ export default {
this.categorySubmenu = null
}
},
getTaskCategory(id) {
if (id.startsWith('chatty')) {
return 'chat'
} else if (id.startsWith('context_chat')) {
return 'context'
} else if (id.includes('translate')) {
return 'translate'
} else if (id.startsWith('richdocuments')) {
return 'generate'
} else if (id.includes('image') || id.includes('sticker')) {
return 'image'
} else if (id.includes('audio') || id.includes('speech')) {
return 'audio'
} else if (id.includes('text')) {
return 'text'
}
return 'other'
},
getTextForCategory(category) {
switch (category) {
case 'chat':
return t('assistant', 'Chat with AI')
case 'context':
return t('assistant', 'Context Chat')
case 'text':
return t('assistant', 'Work with text')
case 'image':
return t('assistant', 'Work with images')
case 'translate':
return t('assistant', 'Translate')
case 'audio':
return t('assistant', 'Work with audio')
case 'generate':
return t('assistant', 'Generate file')
default:
return t('assistant', 'Other')
}
},
getCategoryIcon(category) {
switch (category) {
case 'chat':
Expand Down