diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d31f951d..ad3a9146 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -55,6 +55,7 @@ class Application extends App implements IBootstrap { public const CHAT_USER_INSTRUCTIONS = 'This is a conversation in a specific language between the user and you, Nextcloud Assistant. You are a kind, polite and helpful AI that helps the user to the best of its abilities. If you do not understand something, you will ask for clarification. Detect the language that the user is using. Make sure to use the same language in your response. Do not mention the language explicitly.'; public const CHAT_USER_INSTRUCTIONS_TITLE = 'Above is a chat session in a specific language between the user and you, Nextcloud Assistant. Generate a suitable title summarizing the conversation in the same language. Output only the title in plain text, nothing else.'; + public const MAX_TEXT_INPUT_LENGTH = 64_000; private IAppConfig $appConfig; private IManager $taskProcessingManager; diff --git a/lib/Controller/ChattyLLMController.php b/lib/Controller/ChattyLLMController.php index 2af5b57f..d359312a 100644 --- a/lib/Controller/ChattyLLMController.php +++ b/lib/Controller/ChattyLLMController.php @@ -292,6 +292,9 @@ public function newMessage( if ($this->userId === null) { return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED); } + if (strlen($content) > Application::MAX_TEXT_INPUT_LENGTH) { + return new JSONResponse(['error' => $this->l10n->t('The new message is too long')], Http::STATUS_BAD_REQUEST); + } try { $sessionExists = $this->sessionMapper->exists($this->userId, $sessionId); diff --git a/lib/Service/AssistantService.php b/lib/Service/AssistantService.php index 1998549f..cf4395e9 100644 --- a/lib/Service/AssistantService.php +++ b/lib/Service/AssistantService.php @@ -244,6 +244,11 @@ public function getAvailableTaskTypes(): array { 'id' => 'core:inputList', 'priority' => 0, 'inputShape' => [ + 'textList' => new ShapeDescriptor( + 'Input text list', + 'plop', + EShapeType::ListOfTexts, + ), 'fileList' => new ShapeDescriptor( 'Input file list', 'plop', diff --git a/src/components/AssistantTextProcessingForm.vue b/src/components/AssistantTextProcessingForm.vue index 765c3dcc..62375af7 100644 --- a/src/components/AssistantTextProcessingForm.vue +++ b/src/components/AssistantTextProcessingForm.vue @@ -152,7 +152,7 @@ import TaskList from './TaskList.vue' import TaskTypeSelect from './TaskTypeSelect.vue' import TranslateForm from './Translate/TranslateForm.vue' -import { SHAPE_TYPE_NAMES } from '../constants.js' +import { SHAPE_TYPE_NAMES, MAX_TEXT_INPUT_LENGTH } from '../constants.js' import axios from '@nextcloud/axios' import { generateOcsUrl, generateUrl } from '@nextcloud/router' @@ -330,7 +330,11 @@ export default { } const fieldType = taskType.inputShape[k].type const value = this.myInputs[k] - return ([SHAPE_TYPE_NAMES.Text, SHAPE_TYPE_NAMES.Enum].includes(fieldType) && typeof value === 'string' && !!value?.trim()) + return ([SHAPE_TYPE_NAMES.Text, SHAPE_TYPE_NAMES.Enum].includes(fieldType) + && typeof value === 'string' + && !!value?.trim() + // check that the input text is not too long for text fields + && (fieldType === SHAPE_TYPE_NAMES.Enum || value.trim().length <= MAX_TEXT_INPUT_LENGTH)) || ([ SHAPE_TYPE_NAMES.Number, SHAPE_TYPE_NAMES.File, @@ -338,7 +342,11 @@ export default { SHAPE_TYPE_NAMES.Audio, SHAPE_TYPE_NAMES.Video, ].includes(fieldType) && typeof value === 'number') - || (fieldType === SHAPE_TYPE_NAMES.ListOfTexts && typeof value === 'object' && !!value && value.every(v => typeof v === 'string')) + || (fieldType === SHAPE_TYPE_NAMES.ListOfTexts && typeof value === 'object' && !!value && value.every(v => { + return typeof v === 'string' + && !!v?.trim() + && v.trim().length <= MAX_TEXT_INPUT_LENGTH + })) || (fieldType === SHAPE_TYPE_NAMES.ListOfNumbers && typeof value === 'object' && !!value && value.every(v => typeof v === 'number')) || ([ SHAPE_TYPE_NAMES.ListOfFiles, diff --git a/src/components/ChattyLLM/ChattyLLMInputForm.vue b/src/components/ChattyLLM/ChattyLLMInputForm.vue index 592ac86f..3dbcc2b3 100644 --- a/src/components/ChattyLLM/ChattyLLMInputForm.vue +++ b/src/components/ChattyLLM/ChattyLLMInputForm.vue @@ -128,6 +128,10 @@
{{ t('assistant', 'Output shown here is generated by AI. Make sure to always double-check.') }}
++ {{ t('assistant', 'Messages should not be longer than {maxLength} characters (currently {length}).', { maxLength: 64_000, length: chatContent.length }) }} +