} A promise that resolves the updated agent.
+ */
+ const editAgent = (agent) => {
+ if (DEVELOPMENT) {
+ return _fakeBackend.editAgent(agent);
+ }
+ return $http.put(`${AGENTS_ENDPOINT}`, agent);
+ };
+
/**
* Deletes an agent by its ID from the backend.
* @param {string} id
@@ -163,6 +175,7 @@ function TTYGRestService($http) {
getAgents,
getAgent,
createAgent,
+ editAgent,
deleteAgent
};
}
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 9887c615d..b10ef3468 100644
--- a/src/js/angular/ttyg/controllers/agent-settings-modal.controller.js
+++ b/src/js/angular/ttyg/controllers/agent-settings-modal.controller.js
@@ -33,6 +33,8 @@ function AgentSettingsModalController($scope, $uibModalInstance, SimilarityServi
*/
$scope.agentFormModel = dialogModel.agentFormModel;
+ $scope.isEdit = !!$scope.agentFormModel.id;
+
/**
* The active repository info model.
* @type {RepositoryInfoModel|*}
diff --git a/src/js/angular/ttyg/controllers/ttyg-view.controller.js b/src/js/angular/ttyg/controllers/ttyg-view.controller.js
index 697990fe6..1ddab7b56 100644
--- a/src/js/angular/ttyg/controllers/ttyg-view.controller.js
+++ b/src/js/angular/ttyg/controllers/ttyg-view.controller.js
@@ -11,7 +11,7 @@ import {TTYGEventName} from "../services/ttyg-context.service";
import {AGENTS_FILTER_ALL_KEY} from "../services/constants";
import {AgentListFilterModel} from "../../models/ttyg/agents";
import {ChatsListModel} from "../../models/ttyg/chats";
-import {newAgentFormModelProvider} from "../services/agents.mapper";
+import {agentFormModelMapper, newAgentFormModelProvider} from "../services/agents.mapper";
import {SelectMenuOptionsModel} from "../../models/form-fields";
import {repositoryInfoMapper} from "../../rest/mappers/repositories-mapper";
@@ -230,11 +230,48 @@ function TTYGViewCtrl($rootScope, $scope, $http, $timeout, $translate, $uibModal
};
/**
- * Handles the agent edit operation.
- * @param {AgentModel} agent
+ * Handles the agent edit operation. If the agent is not provided it is assumed that we need to edit the selected
+ * agent which can be obtained from the context service.
+ * @param {AgentModel|undefined} agent
*/
$scope.onEditAgent = (agent) => {
- console.log(`Edit agent`, agent);
+ let agentToEdit = agent;
+ if (!agentToEdit) {
+ agentToEdit = TTYGContextService.getSelectedAgent();
+ }
+ const agentFormModel = agentFormModelMapper(agentToEdit);
+ const activeRepositoryInfo = repositoryInfoMapper($repositories.getActiveRepositoryObject());
+ const options = {
+ templateUrl: 'js/angular/ttyg/templates/modal/agent-settings-modal.html',
+ controller: 'AgentSettingsModalController',
+ windowClass: 'agent-settings-modal',
+ resolve: {
+ dialogModel: function () {
+ return {
+ activeRepositoryInfo: activeRepositoryInfo,
+ activeRepositoryList: $scope.activeRepositoryList,
+ agentFormModel: agentFormModel
+ };
+ }
+ },
+ size: 'lg'
+ };
+ $uibModal.open(options).result.then(
+ // confirmed handler
+ (data) => {
+ TTYGService.editAgent(data)
+ .then((updatedAgent) => {
+ toastr.success($translate.instant("ttyg.agent.messages.agent_save_successfully", {agentName: updatedAgent.name}));
+ const hasSelectedAgent = TTYGContextService.getSelectedAgent();
+ if (hasSelectedAgent && data.id === hasSelectedAgent.id) {
+ TTYGContextService.selectAgent(updatedAgent);
+ }
+ loadAgents(false);
+ })
+ .catch(() => {
+ toastr.error($translate.instant("ttyg.agent.messages.agent_save_failure", {agentName: data.name}));
+ });
+ });
};
// =========================
@@ -267,8 +304,8 @@ function TTYGViewCtrl($rootScope, $scope, $http, $timeout, $translate, $uibModal
});
};
- const loadAgents = () => {
- $scope.loadingAgents = true;
+ const loadAgents = (showLoader = true) => {
+ $scope.loadingAgents = showLoader;
return TTYGService.getAgents()
.then((agents) => {
return TTYGContextService.updateAgents(agents);
diff --git a/src/js/angular/ttyg/directives/agent-list.directive.js b/src/js/angular/ttyg/directives/agent-list.directive.js
index ddd70d79d..18356874e 100644
--- a/src/js/angular/ttyg/directives/agent-list.directive.js
+++ b/src/js/angular/ttyg/directives/agent-list.directive.js
@@ -55,7 +55,7 @@ function AgentListComponent(TTYGContextService, ModalService, $translate) {
* @param {AgentModel} agent
*/
$scope.onEditAgent = (agent) => {
- console.log('Edit agent', agent);
+ TTYGContextService.emit(TTYGEventName.EDIT_AGENT, agent);
};
/**
diff --git a/src/js/angular/ttyg/services/agents.mapper.js b/src/js/angular/ttyg/services/agents.mapper.js
index 3ceb353e9..f360f964f 100644
--- a/src/js/angular/ttyg/services/agents.mapper.js
+++ b/src/js/angular/ttyg/services/agents.mapper.js
@@ -88,6 +88,81 @@ export const newAgentFormModelProvider = () => {
return new AgentFormModel(cloneDeep(AGENT_MODEL_DEFAULT_VALUES));
};
+/**
+ * Converts an angel model to an agent form model.
+ * @param {AgentModel} agentModel
+ * @return {AgentFormModel}
+ */
+export const agentFormModelMapper = (agentModel) => {
+ if (!agentModel) {
+ return;
+ }
+ const agentFormModel = newAgentFormModelProvider();
+ agentFormModel.id = agentModel.id;
+ agentFormModel.name = agentModel.name;
+ agentFormModel.repositoryId = agentModel.repositoryId;
+ agentFormModel.model = agentModel.model;
+ agentFormModel.temperature.value = agentModel.temperature !== undefined ? agentModel.temperature : AGENT_MODEL_DEFAULT_VALUES.temperature.value;
+ agentFormModel.topP.value = agentModel.topP !== undefined ? agentModel.topP : AGENT_MODEL_DEFAULT_VALUES.topP.value;
+ agentFormModel.seed = agentModel.seed;
+ agentFormModel.instructions = agentInstructionsFormMapper(agentModel.instructions);
+ extractionMethodsFormMapper(agentFormModel, agentModel.assistantExtractionMethods);
+ // Select additional methods if they are present in the list returned from the backend (BE).
+ agentFormModel.additionalExtractionMethods.additionalExtractionMethods.forEach((method) => {
+ method.selected = agentModel.additionalExtractionMethods && agentModel.additionalExtractionMethods.some((agentMethod) => agentMethod.method === method.method);
+ });
+
+ return agentFormModel;
+};
+
+/**
+ * @param {AgentInstructionsModel} data
+ * @return {AgentInstructionsFormModel}
+ */
+const agentInstructionsFormMapper = (data) => {
+ if (!data) {
+ return;
+ }
+ return new AgentInstructionsFormModel({
+ systemInstruction: data.systemInstruction,
+ userInstruction: data.userInstruction
+ });
+};
+
+/**
+ * @param {AgentFormModel} agentFormModel
+ * @param {ExtractionMethodModel[]} data
+ */
+const extractionMethodsFormMapper = (agentFormModel, data = []) => {
+ data.forEach((extractionMethod) => {
+ const existingMethod = new ExtractionMethodFormModel({
+ selected: true,
+ method: extractionMethod.method,
+ ontologyGraph: extractionMethod.ontologyGraph,
+ sparqlQuery: extractionMethod.sparqlQuery && new TextFieldModel({
+ value: extractionMethod.sparqlQuery,
+ minLength: 1,
+ maxLength: 2380
+ }),
+ similarityIndex: extractionMethod.similarityIndex,
+ similarityIndexThreshold: extractionMethod.similarityIndexThreshold && new NumericRangeModel({
+ value: extractionMethod.similarityIndexThreshold,
+ minValue: 0,
+ maxValue: 1,
+ step: 0.1
+ }),
+ maxNumberOfTriplesPerCall: extractionMethod.maxNumberOfTriplesPerCall,
+ queryTemplate: extractionMethod.queryTemplate && new TextFieldModel({
+ value: extractionMethod.queryTemplate,
+ minLength: 1,
+ maxLength: 2380
+ }),
+ retrievalConnectorInstance: extractionMethod.retrievalConnectorInstance
+ });
+ agentFormModel.assistantExtractionMethods.setExtractionMethod(existingMethod);
+ });
+};
+
/**
* Converts the response from the server to a list of AgentModel.
* @param {*[]} data
@@ -97,7 +172,7 @@ export const agentListMapper = (data) => {
if (!data) {
return new AgentListModel();
}
- const agentModels = data.map((chat) => agentModelMapper(chat));
+ const agentModels = data.map((agent) => agentModelMapper(agent));
return new AgentListModel(agentModels);
};
diff --git a/src/js/angular/ttyg/services/constants.js b/src/js/angular/ttyg/services/constants.js
index 57f44c903..ef95c1831 100644
--- a/src/js/angular/ttyg/services/constants.js
+++ b/src/js/angular/ttyg/services/constants.js
@@ -1,5 +1,3 @@
-export const AGENT_ID = 'asst_uoKp5kgnPlyZHhRXY7P2r9D7'; // repoId: starwars, method: fts_search
-
/**
* The key to use when filtering agents indicating that all agents should be shown.
* @type {string}
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 a45c2fb58..4c38370dc 100644
--- a/src/js/angular/ttyg/templates/modal/agent-settings-modal.html
+++ b/src/js/angular/ttyg/templates/modal/agent-settings-modal.html
@@ -3,7 +3,7 @@
@@ -330,6 +330,6 @@
{{'ttyg.agent.create_agent_modal.title' | translate}}
diff --git a/src/js/angular/ttyg/templates/ttyg.html b/src/js/angular/ttyg/templates/ttyg.html
index 9e686df89..b5a384ef0 100644
--- a/src/js/angular/ttyg/templates/ttyg.html
+++ b/src/js/angular/ttyg/templates/ttyg.html
@@ -61,7 +61,7 @@