Skip to content

Commit

Permalink
Gdb 10937 fixes links to create similarity and chatgpt pages (#1573)
Browse files Browse the repository at this point in the history
* Fixes the link in the disabled FTS help message to point to the chosen repository in the form, instead of the Workbench-selected one.

* GDB-10937: Update Similarity Extraction Method

## What
Added confirmation dialog for repository change when the user clicks on a link redirecting to the create similarity page.

## Why
The create similarity page depends on the selected repository. To allow the user to create an index in the repository chosen in the create agent dialog, the repository must be changed before navigating to the similarity page if the repository selected in the workbench differs from the one in the dialog.

## How
Added a check to control when the confirmation dialog is displayed and when the user is redirected without prompting.

* GDB-10937: Update ChatGpt Query Methods

## What
Added confirmation dialog for repository change when the user clicks on a link redirecting to the "Create ChatGPT retrieval connector" page.

## Why
The "Create ChatGPT retrieval connector" page depends on the selected repository. To allow the user to create an index in the repository chosen in the create agent dialog, the repository must be changed before navigating to the similarity page if the repository selected in the workbench differs from the one in the dialog.

## How
Added a check to control when the confirmation dialog is displayed and when the user is redirected without prompting.

* GDB-10937: Update Full-text search Query Method

* Enable all tests

* Fixe MR comments
  • Loading branch information
boyan-tonchev authored Oct 2, 2024
1 parent 7687740 commit 60ef053
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 50 deletions.
22 changes: 19 additions & 3 deletions src/i18n/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@
"messages": {
"answer_copy_successful": "The answer was successfully copied to the clipboard.",
"answer_copy_failed": "Failed to copy the answer to the clipboard."
},
"dialog": {
"confirm_repository_change_before_open_similarity": {
"body": "If you proceed with creating the similarity index, GraphDB will open in a new tab and switch to the <b>{{repositoryId}}</b> repository."
},
"confirm_repository_change_before_open_connectors": {
"body": "If you proceed with creating the ChatGPT retrieval connector, GraphDB will open in a new tab and switch to the <b>{{repositoryId}}</b> repository."
}
}
},
"agent": {
Expand Down Expand Up @@ -323,7 +331,7 @@
},
"fts_search": {
"label": "Full-text search",
"fts_disabled_message": "To use this method, you must enable the full-text search (FTS) index on chosen repository and then restart it.<br/>Enable the index: <a href=\"{{repositoryEditPage}}\" target=\"_blank\">here</a>",
"fts_disabled_message": "You must <a href=\"{{repositoryEditPage}}\" target=\"_blank\">enable the full-text search (FTS) index</a> to use this method.",
"missing_repository_id": "Repository ID must be selected"
},
"sparql_search": {
Expand All @@ -342,14 +350,22 @@
"similarity_index": {
"label": "Similarity index name",
"loading_indexes": "Loading similarity indexes...",
"no_similarity_index_message": "To use this method, you must have a similarity index created.<br/>Create similarity text index <a href=\"{{similarityIndexPage}}\" target=\"_blank\">here</a>."
"no_similarity_index": {
"message_1": "You must",
"message_2": "create a similarity index",
"message_3": "to use this method"
}
},
"similarity_threshold": {
"label": "Similarity threshold"
},
"retrieval_search": {
"label": "ChatGPT retrieval connector",
"no_retrieval_connectors_message": "No connector instances.<br/>Create ChatGPT retrieval connector <a href=\"{{retrievalConnectorPage}}\" target=\"_blank\">here</a>."
"no_retrieval_connectors": {
"message_1": "You must",
"message_2": "create ChatGPT retrieval connector",
"message_3": "to use this method"
}
},
"connector_id": {
"label": "ChatGPT retrieval connector"
Expand Down
22 changes: 19 additions & 3 deletions src/i18n/locale-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@
"messages": {
"answer_copy_successful": "La réponse a été copiée avec succès dans le presse-papiers.",
"answer_copy_failed": "Échec de la copie de la réponse dans le presse-papiers."
},
"dialog": {
"confirm_repository_change_before_open_similarity": {
"body": "Si vous continuez à créer l'index de similarité, GraphDB s'ouvrira dans un nouvel onglet et passera au dépôt <b>{{repositoryId}}</b>."
},
"confirm_repository_change_before_open_connectors": {
"body": "Si vous continuez à créer le connecteur de récupération ChatGPT, GraphDB s'ouvrira dans un nouvel onglet et passera au dépôt <b>{{repositoryId}}</b>."
}
}
},
"agent": {
Expand Down Expand Up @@ -324,7 +332,7 @@
},
"fts_search": {
"label": "Recherche en texte intégral",
"fts_disabled_message": "Pour utiliser cette méthode, vous devez activer l'index de recherche en texte intégral (FTS) sur le référentiel choisi, puis le redémarrer.<br/> Activez l'index <a href=\"{{repositoryEditPage}}\" target=\"_blank\">ici</a>.",
"fts_disabled_message": "Vous devez <a href=\"{{repositoryEditPage}}\" target=\"_blank\">activer l'index de recherche en texte intégral (FTS)</a> pour utiliser cette méthode.",
"missing_repository_id": "L'ID du référentiel doit être sélectionné"
},
"sparql_search": {
Expand All @@ -343,14 +351,22 @@
"similarity_index": {
"label": "Nom de l'index de similarité",
"loading_indexes": "Chargement des indices de similarité...",
"no_similarity_index_message": "Pour utiliser cette méthode, vous devez avoir créé un index de similarité.<br/>Créez un index de texte de similarité <a href=\"{{similarityIndexPage}}\" target=\"_blank\">ici</a>."
"no_similarity_index": {
"message_1": "Vous devez",
"message_2": "créer un index de similarité",
"message_3": "pour utiliser cette méthode"
}
},
"similarity_threshold": {
"label": "Seuil de similarité"
},
"retrieval_search": {
"label": "Connecteur de récupération ChatGPT",
"no_retrieval_connectors_message": "Aucune instance de connecteur.<br/>Créez un connecteur de récupération ChatGPT <a href=\"{{retrievalConnectorPage}}\" target=\"_blank\">ici</a>."
"no_retrieval_connectors": {
"message_1": "Vous devez",
"message_2": "créer un connecteur de récupération ChatGPT",
"message_3": "pour utiliser cette méthode"
}
},
"connector_id": {
"label": "Connecteur de récupération ChatGPT"
Expand Down
10 changes: 10 additions & 0 deletions src/js/angular/core/services/repositories.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ repositories.service('$repositories', ['toastr', '$rootScope', '$timeout', '$loc
return repos;
};

/**
* Gets repository by id.
*
* @param {string} repositoryId
* @return {*}
*/
this.getRepository = function (repositoryId) {
return this.getRepositories().find((repository) => repository.id === repositoryId);
};

this.getReadableRepositories = function () {
return _.filter(this.getRepositories(), function (repo) {
return $jwtAuth.canReadRepo(repo);
Expand Down
61 changes: 33 additions & 28 deletions src/js/angular/ttyg/controllers/agent-settings-modal.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'angular/core/services/similarity.service';
import 'angular/core/services/connectors.service';
import 'angular/rest/repositories.rest.service';
import {REPOSITORY_PARAMS} from "../../models/repository/repository";
import {TTYGEventName} from "../services/ttyg-context.service";

angular
.module('graphdb.framework.ttyg.controllers.agent-settings-modal', [
Expand All @@ -13,9 +14,31 @@ angular
])
.controller('AgentSettingsModalController', AgentSettingsModalController);

AgentSettingsModalController.$inject = ['$scope', '$uibModalInstance', 'SimilarityService', 'ConnectorsService', 'RepositoriesRestService', '$sce', 'toastr', 'UriUtils', '$translate', 'dialogModel'];

function AgentSettingsModalController($scope, $uibModalInstance, SimilarityService, ConnectorsService, RepositoriesRestService, $sce, toastr, UriUtils, $translate, dialogModel) {
AgentSettingsModalController.$inject = [
'$scope',
'$uibModalInstance',
'SimilarityService',
'ConnectorsService',
'RepositoriesRestService',
'$sce',
'toastr',
'UriUtils',
'$translate',
'dialogModel',
'TTYGContextService'];

function AgentSettingsModalController(
$scope,
$uibModalInstance,
SimilarityService,
ConnectorsService,
RepositoriesRestService,
$sce,
toastr,
UriUtils,
$translate,
dialogModel,
TTYGContextService) {

// =========================
// Private variables
Expand Down Expand Up @@ -132,42 +155,24 @@ function AgentSettingsModalController($scope, $uibModalInstance, SimilarityServi
const message = decodeHTML(
$translate.instant(
'ttyg.agent.create_agent_modal.form.fts_search.fts_disabled_message',
{repositoryEditPage: '#/repository/edit/' + $scope.activeRepositoryInfo.id}
{repositoryEditPage: '#/repository/edit/' + $scope.agentFormModel.repositoryId}
)
);
return $sce.trustAsHtml(message);
};

/**
* Resolves the hint for the missing similarity index message. This is needed because the hint contains a html link
* that should be properly rendered.
* @return {*}
* Opens the 'Create Similarity' view in a new tab.
*/
$scope.getNoSimilarityIndexHelpMessage = () => {
// The hint contains a html link which should be properly rendered.
const message = decodeHTML(
$translate.instant(
'ttyg.agent.create_agent_modal.form.similarity_index.no_similarity_index_message',
{similarityIndexPage: '#/similarity'}
)
);
return $sce.trustAsHtml(message);
$scope.goToCreateSimilarityView = () => {
TTYGContextService.emit(TTYGEventName.GO_TO_CREATE_SIMILARITY_VIEW, {repositoryId: $scope.agentFormModel.repositoryId});
};

/**
* Resolves the hint for the missing retrieval connector message. This is needed because the hint contains a html
* link that should be properly rendered.
* @return {*}
* Opens the 'Connectors' view in a new tab.
*/
$scope.getNoRetrievalConnectorHelpMessage = () => {
// The hint contains a html link which should be properly rendered.
const message = decodeHTML(
$translate.instant(
'ttyg.agent.create_agent_modal.form.retrieval_search.no_retrieval_connectors_message',
{retrievalConnectorPage: '#/connectors'}
)
);
return $sce.trustAsHtml(message);
$scope.goToConnectorsView = () => {
TTYGContextService.emit(TTYGEventName.GO_TO_CONNECTORS_VIEW, {repositoryId: $scope.agentFormModel.repositoryId});
};

/**
Expand Down
95 changes: 92 additions & 3 deletions src/js/angular/ttyg/controllers/ttyg-view.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {agentFormModelMapper, newAgentFormModelProvider} from "../services/agent
import {SelectMenuOptionsModel} from "../../models/form-fields";
import {repositoryInfoMapper} from "../../rest/mappers/repositories-mapper";
import {saveAs} from 'lib/FileSaver-patch';
import {decodeHTML} from "../../../../app";

const modules = [
'toastr',
Expand All @@ -34,9 +35,37 @@ angular
.module('graphdb.framework.ttyg.controllers.ttyg-view', modules)
.controller('TTYGViewCtrl', TTYGViewCtrl);

TTYGViewCtrl.$inject = ['$rootScope', '$scope', '$http', '$timeout', '$translate', '$uibModal', '$repositories', 'toastr', 'ModalService', 'LocalStorageAdapter', 'TTYGService', 'TTYGContextService', 'TTYGStorageService'];

function TTYGViewCtrl($rootScope, $scope, $http, $timeout, $translate, $uibModal, $repositories, toastr, ModalService, LocalStorageAdapter, TTYGService, TTYGContextService, TTYGStorageService) {
TTYGViewCtrl.$inject = [
'$window',
'$rootScope',
'$scope',
'$http',
'$timeout',
'$translate',
'$uibModal',
'$repositories',
'toastr',
'ModalService',
'LocalStorageAdapter',
'TTYGService',
'TTYGContextService',
'TTYGStorageService'];

function TTYGViewCtrl(
$window,
$rootScope,
$scope,
$http,
$timeout,
$translate,
$uibModal,
$repositories,
toastr,
ModalService,
LocalStorageAdapter,
TTYGService,
TTYGContextService,
TTYGStorageService) {

// =========================
// Private variables
Expand Down Expand Up @@ -598,6 +627,64 @@ function TTYGViewCtrl($rootScope, $scope, $http, $timeout, $translate, $uibModal
});
};

/**
* Opens the create similarity view. It checks if the passed repository ID matches the one selected by the workbench.
* If they do not match, a confirmation dialog is shown to inform the user that the selected repository
* will be automatically changed upon confirmation.
*
* @param {{repositoryId: string}} payload - The payload containing the repository ID.
*/
const onGoToCreateSimilarityView = (payload) => {
if (payload.repositoryId !== $repositories.getActiveRepository()) {
const repository = $repositories.getRepository(payload.repositoryId);
if (repository) {
ModalService.openConfirmation(
$translate.instant('common.confirm'),
decodeHTML($translate.instant('ttyg.chat_panel.dialog.confirm_repository_change_before_open_similarity.body', {repositoryId: repository.id})),
() => {
$repositories.setRepository(repository);
openCreateSimilarityView();
});
}

} else {
openCreateSimilarityView();
}
};

const openCreateSimilarityView = () => {
$window.open('/similarity/index/create', '_blank');
};

/**
* Opens the connectors view. It checks if the passed repository ID matches the one selected by the workbench.
* If they do not match, a confirmation dialog is shown to inform the user that the selected repository
* will be automatically changed upon confirmation.
*
* @param {{repositoryId: string}} payload - The payload containing the repository ID.
*/
const onGoToConnectorsView = (payload) => {
if (payload.repositoryId !== $repositories.getActiveRepository()) {
const repository = $repositories.getRepository(payload.repositoryId);
if (repository) {
ModalService.openConfirmation(
$translate.instant('common.confirm'),
decodeHTML($translate.instant('ttyg.chat_panel.dialog.confirm_repository_change_before_open_connectors.body', {repositoryId: repository.id})),
() => {
$repositories.setRepository(repository);
openConnectorsView();
});
}

} else {
openConnectorsView();
}
};

const openConnectorsView = () => {
$window.open('/connectors', '_blank');
};

/**
* Loads a chat using the chat ID stored in the local storage and selects it.
*/
Expand Down Expand Up @@ -651,6 +738,8 @@ function TTYGViewCtrl($rootScope, $scope, $http, $timeout, $translate, $uibModal
subscriptions.push(TTYGContextService.subscribe(TTYGEventName.AGENT_SELECTED, onAgentSelected));
subscriptions.push(TTYGContextService.subscribe(TTYGEventName.SELECT_CHAT, onChatSelected));
subscriptions.push(TTYGContextService.subscribe(TTYGEventName.COPY_ANSWER_TO_CLIPBOARD, onCopiedAnswerToClipboard));
subscriptions.push(TTYGContextService.subscribe(TTYGEventName.GO_TO_CREATE_SIMILARITY_VIEW, onGoToCreateSimilarityView));
subscriptions.push(TTYGContextService.subscribe(TTYGEventName.GO_TO_CONNECTORS_VIEW, onGoToConnectorsView));
subscriptions.push($rootScope.$on('$translateChangeSuccess', updateLabels));
$scope.$on('$destroy', removeAllListeners);

Expand Down
12 changes: 11 additions & 1 deletion src/js/angular/ttyg/services/ttyg-context.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,15 @@ export const TTYGEventName = {
/**
* This event will be emitted when copying an answer to the clipboard fails.
*/
COPY_ANSWER_TO_CLIPBOARD_FAILURE: 'copyAnswerToClipboardFailure'
COPY_ANSWER_TO_CLIPBOARD_FAILURE: 'copyAnswerToClipboardFailure',

/**
* This event will trigger the opening of the similarity view.
*/
GO_TO_CREATE_SIMILARITY_VIEW: "goToCreateSimilarityView",

/**
* This event will trigger the opening of the connectors view.
*/
GO_TO_CONNECTORS_VIEW: "goToConnectorsView"
};
16 changes: 12 additions & 4 deletions src/js/angular/ttyg/templates/modal/agent-settings-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ <h4 class="modal-title">{{(isEdit ? 'ttyg.agent.create_agent_modal.title.edit '

<div ng-if="extractionMethod.method === extractionMethods.SIMILARITY"
class="extraction-method-options">
<div ng-if="!similarityIndexes.length" class="no-similarity-index-message"
ng-bind-html="getNoSimilarityIndexHelpMessage()">
<div ng-if="!similarityIndexes.length" class="no-similarity-index-message">
{{'ttyg.agent.create_agent_modal.form.similarity_index.no_similarity_index.message_1' | translate}}
<a href="#" ng-click="goToCreateSimilarityView()">
{{'ttyg.agent.create_agent_modal.form.similarity_index.no_similarity_index.message_2' | translate}}
</a>
{{'ttyg.agent.create_agent_modal.form.similarity_index.no_similarity_index.message_3' | translate}}.
</div>
<div ng-show="similarityIndexes.length">
<div class="form-group similarity-index">
Expand Down Expand Up @@ -184,8 +188,12 @@ <h4 class="modal-title">{{(isEdit ? 'ttyg.agent.create_agent_modal.title.edit '

<div ng-if="extractionMethod.method === extractionMethods.RETRIEVAL"
class="extraction-method-options">
<div ng-if="!retrievalConnectors.length" class="no-retrieval-connector-message"
ng-bind-html="getNoRetrievalConnectorHelpMessage()">
<div ng-if="!retrievalConnectors.length" class="no-retrieval-connector-message">
{{'ttyg.agent.create_agent_modal.form.retrieval_search.no_retrieval_connectors.message_1' | translate}}
<a href="#" ng-click="goToConnectorsView()">
{{'ttyg.agent.create_agent_modal.form.retrieval_search.no_retrieval_connectors.message_2' | translate}}
</a>
{{'ttyg.agent.create_agent_modal.form.retrieval_search.no_retrieval_connectors.message_3' | translate}}.
</div>
<div ng-show="retrievalConnectors.length">
<div class="form-group retrieval-connector">
Expand Down
Loading

0 comments on commit 60ef053

Please sign in to comment.