From 10540b261e9903026e8c0d33eb77325bfc54b5fa Mon Sep 17 00:00:00 2001 From: Svilen Velikov <51084653+svilenvelikov@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:44:12 +0300 Subject: [PATCH] GDB-10937 show warnings in agent settings modal (#1622) ## What * Show warning when the user sets temperature higher than 1. * Show warning and an alert to the user when he tries to override the base instructions. ## Why * Because it would help the user to receive more meaningful results from the agent. * Because this would prevent unexpected results if the user provides incorrect instructions. ## How * Implemented icon with tooltip next to the temperature field label, and a handler for the property change to toggle the warning. * Implemented icon with tooltip and an alert that is displayed when the field value becomes different from empty string. Add tests to cover the new features fix test --- src/css/ttyg/agent-settings-modal.css | 8 ++- src/i18n/locale-en.json | 7 ++- src/i18n/locale-fr.json | 7 ++- .../agent-settings-modal.controller.js | 41 +++++++++++++ .../templates/modal/agent-settings-modal.html | 35 +++++++---- test-cypress/fixtures/locale-en.json | 9 ++- .../ttyg/agent/get-agent-defaults.json | 2 +- .../integration/ttyg/create-agent.spec.js | 61 ++++++++++++++++++- .../ttyg/ttyg-agent-settings-modal.steps.js | 18 +++++- 9 files changed, 166 insertions(+), 22 deletions(-) diff --git a/src/css/ttyg/agent-settings-modal.css b/src/css/ttyg/agent-settings-modal.css index 1b49191ec..53ac14b48 100644 --- a/src/css/ttyg/agent-settings-modal.css +++ b/src/css/ttyg/agent-settings-modal.css @@ -1,5 +1,7 @@ :root { --field-label-weight: 500; + --error-color: #FA787E; + --warning-color: #8a6d3b; } .agent-settings-modal .modal-footer .creating-agent-loader { @@ -18,7 +20,11 @@ } .agent-settings-modal .agent-settings-form .has-error { - outline: 1px solid #FA787E; + outline: 1px solid var(--error-color); +} + +.agent-settings-modal .agent-settings-form .has-warning { + outline: 2px solid var(--warning-color); } .agent-settings-modal .agent-settings-form .extraction-methods .extraction-method-heading { diff --git a/src/i18n/locale-en.json b/src/i18n/locale-en.json index 3eb187f86..a001fa3d1 100644 --- a/src/i18n/locale-en.json +++ b/src/i18n/locale-en.json @@ -383,7 +383,8 @@ }, "temperature": { "label": "Temperature", - "tooltip": "The sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic." + "tooltip": "The sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "high_temperature_warning": "A temperature above 1.0 may cause the model to generate anything from creative responses to overdriven, incoherent outputs. Consider lowering the temperature for more reliable results." }, "top_p": { "label": "Top P", @@ -486,6 +487,10 @@ "label": "Base instructions", "placeholder": "Enter base instructions", "tooltip": "Base instructions for the agent. The default value provides good results in most setups so there is no need to change it.", + "overriding_system_instruction_warning": { + "title": "Overriding base instructions", + "body": "Modifying the base instructions may result in suboptimal performance. Only proceed if you are confident in your adjustments." + }, "btn": { "copy_instruction": { "tooltip": "Copy base instructions" diff --git a/src/i18n/locale-fr.json b/src/i18n/locale-fr.json index 87ef02ec1..6d5be01df 100644 --- a/src/i18n/locale-fr.json +++ b/src/i18n/locale-fr.json @@ -383,7 +383,8 @@ }, "temperature": { "label": "Température", - "tooltip": "La température d'échantillonnage à utiliser, entre 0 et 2. Des valeurs plus élevées comme 0,8 rendront la sortie plus aléatoire, tandis que des valeurs plus faibles comme 0,2 la rendront plus ciblée et déterministe." + "tooltip": "La température d'échantillonnage à utiliser, entre 0 et 2. Des valeurs plus élevées comme 0,8 rendront la sortie plus aléatoire, tandis que des valeurs plus faibles comme 0,2 la rendront plus ciblée et déterministe.", + "high_temperature_warning": "Une température supérieure à 1,0 peut amener le modèle à générer des réponses allant de créatives à incohérentes, voire incompréhensibles. Pensez à baisser la température pour des résultats plus fiables." }, "top_p": { "label": "Top P", @@ -486,6 +487,10 @@ "label": "Instructions de base", "placeholder": "Entrez les instructions de base", "tooltip": "Instructions de base pour l'agent. La valeur par défaut fournit de bons résultats dans la plupart des configurations, il n'est donc pas nécessaire de la modifier.", + "overriding_system_instruction_warning": { + "title": "Remplacement des instructions de base", + "body": "Modifier les instructions de base peut entraîner des résultats sous-optimaux. N’effectuez ces changements que si vous êtes sûr de ce que vous faites." + }, "btn": { "copy_instruction": { "tooltip": "Copier les instructions du système" diff --git a/src/js/angular/ttyg/controllers/agent-settings-modal.controller.js b/src/js/angular/ttyg/controllers/agent-settings-modal.controller.js index d0494e9c7..313bac87f 100644 --- a/src/js/angular/ttyg/controllers/agent-settings-modal.controller.js +++ b/src/js/angular/ttyg/controllers/agent-settings-modal.controller.js @@ -19,6 +19,7 @@ angular AgentSettingsModalController.$inject = [ '$scope', '$uibModalInstance', + 'ModalService', 'SimilarityService', 'ConnectorsService', 'RepositoriesRestService', @@ -33,6 +34,7 @@ AgentSettingsModalController.$inject = [ function AgentSettingsModalController( $scope, $uibModalInstance, + ModalService, SimilarityService, ConnectorsService, RepositoriesRestService, @@ -106,6 +108,18 @@ function AgentSettingsModalController( */ $scope.showAdvancedSettings = false; + /** + * Flag used to show/hide the high temperature warning in the modal. + * @type {boolean} + */ + $scope.showHighTemperatureWarning = false; + + /** + * Flag used to control the visibility of the system instruction warning. + * @type {boolean} + */ + $scope.showSystemInstructionWarning = false; + /** * The similarity indexes to be used for the similarity extraction method as select menu options. * @type {SelectMenuOptionsModel[]} @@ -283,6 +297,33 @@ function AgentSettingsModalController( $scope.agentFormModel.instructions.userInstruction = $scope.agentFormModel.instructions.userInstructionCopy; }; + /** + * Handles the change in the temperature field. This is needed because the high temperature warning should be shown + * when the temperature is higher than 1. + */ + $scope.onTemperatureChange = () => { + $scope.showHighTemperatureWarning = $scope.agentFormModel.temperature.value > 1; + }; + + /** + * Handles the change in the system instructions field. + */ + $scope.onSystemInstructionChange = () => { + if ($scope.agentFormModel.instructions.systemInstruction !== '' && !$scope.showSystemInstructionWarning) { + $scope.showSystemInstructionWarning = true; + ModalService.openModalAlert({ + title: $translate.instant('ttyg.agent.create_agent_modal.form.system_instruction.overriding_system_instruction_warning.title'), + message: $translate.instant('ttyg.agent.create_agent_modal.form.system_instruction.overriding_system_instruction_warning.body') + }).result + .then(function () { + // Do nothing, just warning the user + }); + } + if ($scope.agentFormModel.instructions.systemInstruction === '') { + $scope.showSystemInstructionWarning = false; + } + }; + // ========================= // Private functions // ========================= diff --git a/src/js/angular/ttyg/templates/modal/agent-settings-modal.html b/src/js/angular/ttyg/templates/modal/agent-settings-modal.html index 24c68c35d..8b265299a 100644 --- a/src/js/angular/ttyg/templates/modal/agent-settings-modal.html +++ b/src/js/angular/ttyg/templates/modal/agent-settings-modal.html @@ -321,7 +321,7 @@