From 8093b5a93a5cc4e907f097855e20a146b30ef0fb Mon Sep 17 00:00:00 2001 From: David Gauldie Date: Fri, 1 Nov 2024 17:46:10 -0400 Subject: [PATCH 1/4] if we can't find a grounding, we set as a default empty grounding --- .../gollm_openai/prompts/latex_style_guide.py | 1 + .../controller/gollm/GoLLMController.java | 35 ++++++++++++--- .../knowledge/KnowledgeController.java | 43 ++++++++++++++++--- .../models/dataservice/model/Model.java | 12 ++++++ .../service/tasks/TaskUtilities.java | 2 + .../src/main/resources/messages.properties | 1 + 6 files changed, 82 insertions(+), 12 deletions(-) diff --git a/packages/gollm/gollm_openai/prompts/latex_style_guide.py b/packages/gollm/gollm_openai/prompts/latex_style_guide.py index 70b400bfbe..f62e7ec5d8 100644 --- a/packages/gollm/gollm_openai/prompts/latex_style_guide.py +++ b/packages/gollm/gollm_openai/prompts/latex_style_guide.py @@ -14,4 +14,5 @@ 11) Do not use "\\cdot" or "*" to indicate multiplication. Use whitespace instead. 12) Replace "\\epsilon" with "\\varepsilon" when representing a parameter or variable 13) Avoid using notation for mathematical constants like "e" and "pi". Use their actual values up to 3 decimal places instead. +14) If equations are separated by commas, do not include commas in the LaTeX code. """ diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java index 30f1bbd77e..ef2c10fffd 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java @@ -858,32 +858,57 @@ public ResponseEntity createEnrichModelMetadataTask( // Update State Grounding if (!model.isRegnet()) { final List states = model.getStates(); - states.forEach(state -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state)); + states.forEach(state -> { + if (state == null) { + state = new State(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state); + }); model.setStates(states); } else if (model.isRegnet()) { final List vertices = model.getVerticies(); - vertices.forEach(vertex -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex)); + vertices.forEach(vertex -> { + if (vertex == null) { + vertex = new RegNetVertex(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex); + }); model.setVerticies(vertices); } // Update Observable Grounding if (model.getObservables() != null && !model.getObservables().isEmpty()) { final List observables = model.getObservables(); - observables.forEach(observable -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable)); + observables.forEach(observable -> { + if (observable == null) { + observable = new Observable(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable); + }); model.setObservables(observables); } // Update Parameter Grounding if (model.getParameters() != null && !model.getParameters().isEmpty()) { final List parameters = model.getParameters(); - parameters.forEach(parameter -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter)); + parameters.forEach(parameter -> { + if (parameter == null) { + parameter = new ModelParameter(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter); + }); model.setParameters(parameters); } // Update Transition Grounding if (model.getTransitions() != null && !model.getTransitions().isEmpty()) { final List transitions = model.getTransitions(); - transitions.forEach(transition -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition)); + transitions.forEach(transition -> { + if (transition == null) { + transition = new Transition(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition); + }); model.setTransitions(transitions); } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java index fd210d9039..3005be13b4 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java @@ -230,34 +230,59 @@ private void enrichModel( } // Update State Grounding - if (!model.get().isRegnet()) { + if (model.get().isPetrinet()) { List states = model.get().getStates(); - states.forEach(state -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state)); + states.forEach(state -> { + if (state == null) { + state = new State(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state); + }); model.get().setStates(states); - } else if (model.get().isRegnet()) { + } else { List vertices = model.get().getVerticies(); - vertices.forEach(vertex -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex)); + vertices.forEach(vertex -> { + if (vertex == null) { + vertex = new RegNetVertex(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex); + }); model.get().setVerticies(vertices); } //Update Observable Grounding if (model.get().getObservables() != null && !model.get().getObservables().isEmpty()) { List observables = model.get().getObservables(); - observables.forEach(observable -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable)); + observables.forEach(observable -> { + if (observable == null) { + observable = new Observable(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable); + }); model.get().setObservables(observables); } //Update Parameter Grounding if (model.get().getParameters() != null && !model.get().getParameters().isEmpty()) { List parameters = model.get().getParameters(); - parameters.forEach(parameter -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter)); + parameters.forEach(parameter -> { + if (parameter == null) { + parameter = new ModelParameter(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter); + }); model.get().setParameters(parameters); } //Update Transition Grounding if (model.get().getTransitions() != null && !model.get().getTransitions().isEmpty()) { List transitions = model.get().getTransitions(); - transitions.forEach(transition -> TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition)); + transitions.forEach(transition -> { + if (transition == null) { + transition = new Transition(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition); + }); model.get().setTransitions(transitions); } @@ -372,6 +397,10 @@ public ResponseEntity equationsToModel( throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("skema.internal-error")); } + if (!responseAMR.isPetrinet()) { + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("skema.bad-equations.petrinet")); + } + // If no model id is provided, create a new model asset if (modelId == null) { try { diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java index b675727929..59c23b08b4 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java @@ -342,4 +342,16 @@ public boolean isRegnet() { } return this.getHeader().getSchemaName().equalsIgnoreCase("regnet"); } + + @JsonIgnore + @TSIgnore + public boolean isPetrinet() { + if (this.getHeader() == null) { + return false; + } + if (this.getHeader().getSchemaName() == null) { + return false; + } + return this.getHeader().getSchemaName().equalsIgnoreCase("petrinet"); + } } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java index ded439dccf..4e2d592995 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java @@ -109,6 +109,8 @@ public static void performDKGSearchAndSetGrounding(MIRAProxy miraProxy, Grounded if (part.getGrounding().getIdentifiers() == null) part.getGrounding().setIdentifiers(new HashMap<>()); String[] currieId = dkg.getCurie().split(":"); part.getGrounding().getIdentifiers().put(currieId[0], currieId[1]); + } else { + part.setGrounding(new ModelGrounding()); } } } diff --git a/packages/server/src/main/resources/messages.properties b/packages/server/src/main/resources/messages.properties index c6a9fb48ca..16a34cc14b 100644 --- a/packages/server/src/main/resources/messages.properties +++ b/packages/server/src/main/resources/messages.properties @@ -74,6 +74,7 @@ rebac.unauthorized-update = You're not authorized to update this resource. Conta skema.bad-code = Our model service (SKEMA) couldn't find a valid model representation. This could be due to syntax or semantic errors in your code. Please review your code snippet and try again. skema.bad-equations = Our model service (SKEMA) couldn't find a valid model representation. This could be due to invalid equations or an inability to parse them into the requested framework. Please review your equations and try again. +skema.bad-equations.petrinet = Our model service (SKEMA) couldn't create a valid Petrinet representation for the supplied equations. This could be due to invalid equations or an inability to parse them into the requested framework. Please review your equations and try again. skema.error.align-model = We couldn't align the model with the selected document. Please verify that the model is valid and that the document has valid extractions. skema.error.image-2-equation = We couldn't convert the equation image into valid LaTeX. Please verify that the image is of a valid equation. skema.internal-error = We couldn't produce a valid model representation based on the selected resource. Please verify that the resource is valid and try again. From d0f05e2083dea1aea5a532fa2c556d0cf63caaef Mon Sep 17 00:00:00 2001 From: David Gauldie Date: Mon, 4 Nov 2024 13:32:23 -0500 Subject: [PATCH 2/4] refactor controller to a common service method --- .../controller/gollm/GoLLMController.java | 158 +------------- .../knowledge/KnowledgeController.java | 200 +++--------------- .../hmiserver/service/data/ModelService.java | 174 ++++++++++++++- 3 files changed, 205 insertions(+), 327 deletions(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java index ef2c10fffd..2e0663186a 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java @@ -41,12 +41,6 @@ import software.uncharted.terarium.hmiserver.models.dataservice.dataset.Dataset; import software.uncharted.terarium.hmiserver.models.dataservice.document.DocumentAsset; import software.uncharted.terarium.hmiserver.models.dataservice.model.Model; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Observable; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.State; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Transition; -import software.uncharted.terarium.hmiserver.models.dataservice.regnet.RegNetVertex; -import software.uncharted.terarium.hmiserver.models.task.CompoundTask; import software.uncharted.terarium.hmiserver.models.task.TaskRequest; import software.uncharted.terarium.hmiserver.models.task.TaskRequest.TaskType; import software.uncharted.terarium.hmiserver.models.task.TaskResponse; @@ -771,151 +765,21 @@ public ResponseEntity createEnrichModelMetadataTask( projectId ); - // Grab the document - final Optional document = documentAssetService.getAsset(documentId, permission); - - // make sure there is text in the document. We don't need a document but if we - // do have one it can't be empty - if (document.isPresent() && (document.get().getText() == null || document.get().getText().isEmpty())) { - log.warn(String.format("Document %s has no extracted text", documentId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("document.extraction.not-done")); - } - - // Grab the model - Optional modelOptional = modelService.getAsset(modelId, permission); - if (modelOptional.isEmpty()) { - log.warn(String.format("Model %s not found", modelId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("model.not-found")); - } - - final TaskRequest req; - - if (document.isPresent()) { - final TaskRequest enrichAmrRequest; - try { - enrichAmrRequest = TaskUtilities.getEnrichAMRTaskRequest( - currentUserService.get().getId(), - document.orElse(null), - modelOptional.get(), - projectId, - overwrite - ); - } catch (final IOException e) { - log.error("Unable to create Enrich AMR task", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.write")); - } - - final TaskRequest modelCardRequest; - try { - modelCardRequest = TaskUtilities.getModelCardTask( - currentUserService.get().getId(), - document.orElse(null), - modelOptional.get(), - projectId - ); - } catch (final IOException e) { - log.error("Unable to create Model Card task", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.write")); - } - - req = new CompoundTask(enrichAmrRequest, modelCardRequest); - } else { - try { - req = TaskUtilities.getModelCardTask(currentUserService.get().getId(), null, modelOptional.get(), projectId); - } catch (final IOException e) { - log.error("Unable to create Model Card task", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.write")); - } - } - final TaskResponse resp; try { - resp = taskService.runTask(mode, req); - } catch (final JsonProcessingException e) { - log.error("Unable to serialize input", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("task.gollm.json-processing")); - } catch (final TimeoutException e) { - log.warn("Timeout while waiting for task response", e); - throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("task.gollm.timeout")); - } catch (final InterruptedException e) { - log.warn("Interrupted while waiting for task response", e); - throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("task.gollm.interrupted")); - } catch (final ExecutionException e) { + resp = modelService.enrichModel(projectId, Optional.of(documentId), modelId, permission, true); + } catch (final IOException e) { + log.error("An error occurred while trying to retrieve information necessary for model enrichment.", e); + throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("postgres.service-unavailable")); + } catch (ExecutionException e) { log.error("Error while waiting for task response", e); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("task.gollm.execution-failure")); - } - - // at this point the initial enrichment has happened. - modelOptional = modelService.getAsset(modelId, permission); - if (modelOptional.isEmpty()) { - // this would be a very strange case - log.warn(String.format("Model %s not found", modelId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("model.not-found")); - } - - final Model model = modelOptional.get(); - - // Update State Grounding - if (!model.isRegnet()) { - final List states = model.getStates(); - states.forEach(state -> { - if (state == null) { - state = new State(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state); - }); - model.setStates(states); - } else if (model.isRegnet()) { - final List vertices = model.getVerticies(); - vertices.forEach(vertex -> { - if (vertex == null) { - vertex = new RegNetVertex(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex); - }); - model.setVerticies(vertices); - } - - // Update Observable Grounding - if (model.getObservables() != null && !model.getObservables().isEmpty()) { - final List observables = model.getObservables(); - observables.forEach(observable -> { - if (observable == null) { - observable = new Observable(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable); - }); - model.setObservables(observables); - } - - // Update Parameter Grounding - if (model.getParameters() != null && !model.getParameters().isEmpty()) { - final List parameters = model.getParameters(); - parameters.forEach(parameter -> { - if (parameter == null) { - parameter = new ModelParameter(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter); - }); - model.setParameters(parameters); - } - - // Update Transition Grounding - if (model.getTransitions() != null && !model.getTransitions().isEmpty()) { - final List transitions = model.getTransitions(); - transitions.forEach(transition -> { - if (transition == null) { - transition = new Transition(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition); - }); - model.setTransitions(transitions); - } - - try { - modelService.updateAsset(model, projectId, permission); - } catch (final IOException e) { - throw new RuntimeException(e); + } catch (InterruptedException e) { + log.warn("Interrupted while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("task.gollm.interrupted")); + } catch (TimeoutException e) { + log.warn("Timeout while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("task.gollm.timeout")); } return ResponseEntity.ok().body(resp); diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java index 3005be13b4..351f9e29b8 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java @@ -55,16 +55,10 @@ import software.uncharted.terarium.hmiserver.models.dataservice.model.Model; import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelHeader; import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelMetadata; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Observable; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.State; -import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Transition; import software.uncharted.terarium.hmiserver.models.dataservice.provenance.Provenance; import software.uncharted.terarium.hmiserver.models.dataservice.provenance.ProvenanceRelationType; import software.uncharted.terarium.hmiserver.models.dataservice.provenance.ProvenanceType; -import software.uncharted.terarium.hmiserver.models.dataservice.regnet.RegNetVertex; import software.uncharted.terarium.hmiserver.models.extractionservice.ExtractionResponse; -import software.uncharted.terarium.hmiserver.models.task.CompoundTask; import software.uncharted.terarium.hmiserver.models.task.TaskRequest; import software.uncharted.terarium.hmiserver.models.task.TaskRequest.TaskType; import software.uncharted.terarium.hmiserver.models.task.TaskResponse; @@ -81,11 +75,9 @@ import software.uncharted.terarium.hmiserver.service.data.ProjectService; import software.uncharted.terarium.hmiserver.service.data.ProvenanceSearchService; import software.uncharted.terarium.hmiserver.service.data.ProvenanceService; -import software.uncharted.terarium.hmiserver.service.tasks.EnrichAmrResponseHandler; import software.uncharted.terarium.hmiserver.service.tasks.EquationsCleanupResponseHandler; import software.uncharted.terarium.hmiserver.service.tasks.TaskService; import software.uncharted.terarium.hmiserver.service.tasks.TaskService.TaskMode; -import software.uncharted.terarium.hmiserver.service.tasks.TaskUtilities; import software.uncharted.terarium.hmiserver.utils.ByteMultipartFile; import software.uncharted.terarium.hmiserver.utils.Messages; import software.uncharted.terarium.hmiserver.utils.StringMultipartFile; @@ -130,169 +122,6 @@ void init() { taskService.addResponseHandler(equationsCleanupResponseHandler); } - private void enrichModel( - final UUID projectId, - final UUID documentId, - final UUID modelId, - final Schema.Permission permission, - final boolean overwrite - ) { - // Grab the document - final Optional document = documentAssetService.getAsset(documentId, permission); - if (document.isEmpty()) { - log.warn(String.format("Document %s not found", documentId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("document.not-found")); - } - - // make sure there is text in the document - if (document.get().getText() == null || document.get().getText().isEmpty()) { - log.warn(String.format("Document %s has no extracted text", documentId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("document.extraction.not-done")); - } - - // Grab the model - Optional model = modelService.getAsset(modelId, permission); - if (model.isEmpty()) { - log.warn(String.format("Model %s not found", modelId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("model.not-found")); - } - - final EnrichAmrResponseHandler.Input input = new EnrichAmrResponseHandler.Input(); - try { - input.setResearchPaper(mapper.writeValueAsString(document.get().getExtractions())); - } catch (JsonProcessingException e) { - log.error("Unable to serialize document text", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.write")); - } - // stripping the metadata from the model before its sent since it can cause - // gollm to fail with massive inputs - model.get().setMetadata(null); - - try { - final String amr = mapper.writeValueAsString(model.get()); - input.setAmr(amr); - } catch (final JsonProcessingException e) { - log.error("Unable to serialize model card", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("task.gollm.json-processing")); - } - - // Create the tasks - final TaskRequest enrichAmrRequest; - try { - enrichAmrRequest = TaskUtilities.getEnrichAMRTaskRequest( - currentUserService.get().getId(), - document.get(), - model.get(), - projectId, - overwrite - ); - } catch (IOException e) { - log.error("Unable to create Enrich AMR task", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.write")); - } - - final TaskRequest modelCardRequest; - try { - modelCardRequest = TaskUtilities.getModelCardTask( - currentUserService.get().getId(), - document.get(), - model.get(), - projectId - ); - } catch (IOException e) { - log.error("Unable to create Model Card task", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.write")); - } - - final TaskRequest req = new CompoundTask(enrichAmrRequest, modelCardRequest); - try { - taskService.runTask(TaskMode.SYNC, req); - } catch (final JsonProcessingException e) { - log.error("Unable to serialize input", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("task.gollm.json-processing")); - } catch (final TimeoutException e) { - log.warn("Timeout while waiting for task response", e); - throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("task.gollm.timeout")); - } catch (final InterruptedException e) { - log.warn("Interrupted while waiting for task response", e); - throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("task.gollm.interrupted")); - } catch (final ExecutionException e) { - log.error("Error while waiting for task response", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("task.gollm.execution-failure")); - } - - // at this point the initial enrichment has happened. - model = modelService.getAsset(modelId, permission); - if (model.isEmpty()) { - //this would be a very strange case - log.warn(String.format("Model %s not found", modelId)); - throw new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("model.not-found")); - } - - // Update State Grounding - if (model.get().isPetrinet()) { - List states = model.get().getStates(); - states.forEach(state -> { - if (state == null) { - state = new State(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state); - }); - model.get().setStates(states); - } else { - List vertices = model.get().getVerticies(); - vertices.forEach(vertex -> { - if (vertex == null) { - vertex = new RegNetVertex(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex); - }); - model.get().setVerticies(vertices); - } - - //Update Observable Grounding - if (model.get().getObservables() != null && !model.get().getObservables().isEmpty()) { - List observables = model.get().getObservables(); - observables.forEach(observable -> { - if (observable == null) { - observable = new Observable(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable); - }); - model.get().setObservables(observables); - } - - //Update Parameter Grounding - if (model.get().getParameters() != null && !model.get().getParameters().isEmpty()) { - List parameters = model.get().getParameters(); - parameters.forEach(parameter -> { - if (parameter == null) { - parameter = new ModelParameter(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter); - }); - model.get().setParameters(parameters); - } - - //Update Transition Grounding - if (model.get().getTransitions() != null && !model.get().getTransitions().isEmpty()) { - List transitions = model.get().getTransitions(); - transitions.forEach(transition -> { - if (transition == null) { - transition = new Transition(); - } - TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition); - }); - model.get().setTransitions(transitions); - } - - try { - modelService.updateAsset(model.get(), projectId, permission); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - /** * Send the equations to the skema unified service to get the AMR * @@ -407,12 +236,24 @@ public ResponseEntity equationsToModel( final Model model = modelService.createAsset(responseAMR, projectId, permission); // enrich the model with the document if (documentId != null) { - enrichModel(projectId, documentId, model.getId(), permission, true); + modelService.enrichModel(projectId, Optional.of(documentId), model.getId(), permission, true); } return ResponseEntity.ok(model.getId()); } catch (final IOException e) { - log.error("An error occurred while trying to create a Model asset.", e); + log.error("An error occurred while trying to retrieve information necessary for model enrichment.", e); throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("postgres.service-unavailable")); + } catch (ExecutionException e) { + log.error("Error while waiting for task response", e); + throw new ResponseStatusException( + HttpStatus.INTERNAL_SERVER_ERROR, + messages.get("task.gollm.execution-failure") + ); + } catch (InterruptedException e) { + log.warn("Interrupted while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("task.gollm.interrupted")); + } catch (TimeoutException e) { + log.warn("Timeout while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("task.gollm.timeout")); } } @@ -430,12 +271,21 @@ public ResponseEntity equationsToModel( modelService.updateAsset(responseAMR, projectId, permission); // enrich the model with the document if (documentId != null) { - enrichModel(projectId, documentId, responseAMR.getId(), permission, true); + modelService.enrichModel(projectId, Optional.of(documentId), responseAMR.getId(), permission, true); } return ResponseEntity.ok(model.get().getId()); } catch (final IOException e) { - log.error(String.format("Unable to update the model with id %s.", modelId), e); + log.error("An error occurred while trying to retrieve information necessary for model enrichment.", e); throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("postgres.service-unavailable")); + } catch (ExecutionException e) { + log.error("Error while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("task.gollm.execution-failure")); + } catch (InterruptedException e) { + log.warn("Interrupted while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("task.gollm.interrupted")); + } catch (TimeoutException e) { + log.warn("Timeout while waiting for task response", e); + throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("task.gollm.timeout")); } } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java index 39296f55fc..f03237021f 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java @@ -9,41 +9,65 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import lombok.extern.slf4j.Slf4j; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import software.uncharted.terarium.hmiserver.configuration.Config; import software.uncharted.terarium.hmiserver.configuration.ElasticsearchConfiguration; import software.uncharted.terarium.hmiserver.models.TerariumAssetEmbeddings; +import software.uncharted.terarium.hmiserver.models.dataservice.document.DocumentAsset; import software.uncharted.terarium.hmiserver.models.dataservice.model.Model; import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelDescription; import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelMetadata; +import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter; import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.metadata.Annotations; +import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Observable; +import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.State; +import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Transition; +import software.uncharted.terarium.hmiserver.models.dataservice.regnet.RegNetVertex; +import software.uncharted.terarium.hmiserver.models.task.CompoundTask; +import software.uncharted.terarium.hmiserver.models.task.TaskRequest; +import software.uncharted.terarium.hmiserver.models.task.TaskResponse; +import software.uncharted.terarium.hmiserver.proxies.mira.MIRAProxy; import software.uncharted.terarium.hmiserver.repository.data.ModelRepository; +import software.uncharted.terarium.hmiserver.service.CurrentUserService; import software.uncharted.terarium.hmiserver.service.elasticsearch.ElasticsearchService; import software.uncharted.terarium.hmiserver.service.gollm.EmbeddingService; import software.uncharted.terarium.hmiserver.service.s3.S3ClientService; +import software.uncharted.terarium.hmiserver.service.tasks.TaskService; +import software.uncharted.terarium.hmiserver.service.tasks.TaskUtilities; import software.uncharted.terarium.hmiserver.utils.rebac.Schema; @Slf4j @Service public class ModelService extends TerariumAssetServiceWithSearch { + private final CurrentUserService currentUserService; + private final DocumentAssetService documentAssetService; private final EmbeddingService embeddingService; + private final TaskService taskService; private final Environment env; + private final MIRAProxy miraProxy; + public ModelService( - final ObjectMapper objectMapper, final Config config, + final CurrentUserService currentUserService, + final DocumentAssetService documentAssetService, final ElasticsearchConfiguration elasticConfig, final ElasticsearchService elasticService, - final ProjectService projectService, + final EmbeddingService embeddingService, + final Environment env, + final MIRAProxy miraProxy, + final ModelRepository repository, + final ObjectMapper objectMapper, final ProjectAssetService projectAssetService, + final ProjectService projectService, final S3ClientService s3ClientService, - final ModelRepository repository, - final EmbeddingService embeddingService, - final Environment env + final TaskService taskService ) { super( objectMapper, @@ -56,8 +80,12 @@ public ModelService( repository, Model.class ); + this.currentUserService = currentUserService; + this.documentAssetService = documentAssetService; this.embeddingService = embeddingService; this.env = env; + this.miraProxy = miraProxy; + this.taskService = taskService; } private boolean isRunningTestProfile() { @@ -233,4 +261,140 @@ public Optional updateAsset( return updatedOptional; } + + public TaskResponse enrichModel( + final UUID projectId, + final Optional documentId, + final UUID modelId, + final Schema.Permission permission, + final boolean overwrite + ) throws IOException, ExecutionException, InterruptedException, TimeoutException { + // Grab the document + final Optional document = documentAssetService.getAsset(documentId.get(), permission); + if (document.isEmpty()) { + String errorString = String.format("Document %s not found", documentId); + log.warn(errorString); + throw new IOException(errorString); + } + + // make sure there is text in the document + if (document.get().getText() == null || document.get().getText().isEmpty()) { + String errorString = String.format("Document %s has no extracted text", documentId); + log.warn(errorString); + throw new IOException(errorString); + } + + // Grab the model + Optional model = getAsset(modelId, permission); + if (model.isEmpty()) { + String errorString = String.format("Model %s not found", modelId); + log.warn(errorString); + throw new IOException(errorString); + } + + // stripping the metadata from the model before its sent since it can cause + // gollm to fail with massive inputs + model.get().setMetadata(null); + + final TaskRequest req; + + if (document.isPresent()) { + // Create the tasks + final TaskRequest enrichAmrRequest = TaskUtilities.getEnrichAMRTaskRequest( + currentUserService.get().getId(), + document.get(), + model.get(), + projectId, + overwrite + ); + + final TaskRequest modelCardRequest = TaskUtilities.getModelCardTask( + currentUserService.get().getId(), + document.get(), + model.get(), + projectId + ); + + req = new CompoundTask(enrichAmrRequest, modelCardRequest); + } else { + req = TaskUtilities.getModelCardTask(currentUserService.get().getId(), null, model.get(), projectId); + } + + final TaskResponse resp = taskService.runTask(TaskService.TaskMode.SYNC, req); + + // at this point the initial enrichment has happened. + model = getAsset(modelId, permission); + if (model.isEmpty()) { + String errorString = String.format("Model %s not found", modelId); + log.warn(errorString); + throw new IOException(errorString); + } + + // Update State Grounding + if (model.get().isRegnet()) { + List vertices = model.get().getVerticies(); + vertices.forEach(vertex -> { + if (vertex == null) { + vertex = new RegNetVertex(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex); + }); + model.get().setVerticies(vertices); + } else { + List states = model.get().getStates(); + states.forEach(state -> { + if (state == null) { + state = new State(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state); + }); + model.get().setStates(states); + } + + //Update Observable Grounding + if (model.get().getObservables() != null && !model.get().getObservables().isEmpty()) { + List observables = model.get().getObservables(); + observables.forEach(observable -> { + if (observable == null) { + observable = new Observable(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable); + }); + model.get().setObservables(observables); + } + + //Update Parameter Grounding + if (model.get().getParameters() != null && !model.get().getParameters().isEmpty()) { + List parameters = model.get().getParameters(); + parameters.forEach(parameter -> { + if (parameter == null) { + parameter = new ModelParameter(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter); + }); + model.get().setParameters(parameters); + } + + //Update Transition Grounding + if (model.get().getTransitions() != null && !model.get().getTransitions().isEmpty()) { + List transitions = model.get().getTransitions(); + transitions.forEach(transition -> { + if (transition == null) { + transition = new Transition(); + } + TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition); + }); + model.get().setTransitions(transitions); + } + + try { + updateAsset(model.get(), projectId, permission); + } catch (IOException e) { + String errorString = String.format("Failed to update model %s", modelId); + log.warn(errorString); + throw new IOException(errorString); + } + + return resp; + } } From 68f15e984fcc99d5d2895d598082aa7617382664 Mon Sep 17 00:00:00 2001 From: David Gauldie Date: Mon, 4 Nov 2024 20:00:11 -0500 Subject: [PATCH 3/4] remove open session in view --- .../client/hmi-client/src/services/goLLM.ts | 2 +- .../controller/gollm/GoLLMController.java | 25 ++++++--- .../knowledge/KnowledgeController.java | 8 +-- .../PSCrudSoftDeleteRepository.java | 3 +- .../hmiserver/service/data/ModelService.java | 55 +++++++++---------- .../TerariumAssetServiceWithoutSearch.java | 8 +-- .../service/tasks/TaskUtilities.java | 2 + .../src/main/resources/application.properties | 11 ++-- 8 files changed, 60 insertions(+), 54 deletions(-) diff --git a/packages/client/hmi-client/src/services/goLLM.ts b/packages/client/hmi-client/src/services/goLLM.ts index cd43df6fd6..d99296fbf8 100644 --- a/packages/client/hmi-client/src/services/goLLM.ts +++ b/packages/client/hmi-client/src/services/goLLM.ts @@ -39,7 +39,7 @@ export async function interventionPolicyFromDocument( export async function enrichModelMetadata(modelId: string, documentId: string, overwrite: boolean): Promise { try { - await API.get('/gollm/enrich-model-metadata', { + await API.get('/gollm/enrich-model-metadata', { params: { 'model-id': modelId, 'document-id': documentId, diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java index 2e0663186a..3151ee260e 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/gollm/GoLLMController.java @@ -41,6 +41,7 @@ import software.uncharted.terarium.hmiserver.models.dataservice.dataset.Dataset; import software.uncharted.terarium.hmiserver.models.dataservice.document.DocumentAsset; import software.uncharted.terarium.hmiserver.models.dataservice.model.Model; +import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelMetadata; import software.uncharted.terarium.hmiserver.models.task.TaskRequest; import software.uncharted.terarium.hmiserver.models.task.TaskRequest.TaskType; import software.uncharted.terarium.hmiserver.models.task.TaskResponse; @@ -263,7 +264,7 @@ public ResponseEntity createConfigureModelFromDocumentTask( // stripping the metadata from the model before its sent since it can cause // gollm to fail with massive inputs - model.get().setMetadata(null); + model.get().setMetadata(new ModelMetadata()); input.setAmr(model.get().serializeWithoutTerariumFields(new String[] { "id" }, null)); // Create the task @@ -391,7 +392,7 @@ public ResponseEntity createConfigureModelFromDatasetTask( input.setDataset(dataArray); // stripping the metadata from the model before its sent since it can cause // gollm to fail with massive inputs - model.get().setMetadata(null); + model.get().setMetadata(new ModelMetadata()); input.setAmr(model.get().serializeWithoutTerariumFields(null, null)); // set matrix string if provided @@ -506,7 +507,7 @@ public ResponseEntity createInterventionsFromDocumentTask( // stripping the metadata from the model before its sent since it can cause // gollm to fail with massive inputs - model.get().setMetadata(null); + model.get().setMetadata(new ModelMetadata()); input.setAmr(model.get().serializeWithoutTerariumFields(new String[] { "id" }, null)); // Create the task @@ -742,7 +743,7 @@ public ResponseEntity createGenerateResponseTask( description = "Dispatched successfully", content = @Content( mediaType = "application/json", - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = TaskResponse.class) + schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = UUID.class) ) ), @ApiResponse( @@ -753,10 +754,10 @@ public ResponseEntity createGenerateResponseTask( @ApiResponse(responseCode = "500", description = "There was an issue dispatching the request", content = @Content) } ) - public ResponseEntity createEnrichModelMetadataTask( + public ResponseEntity createEnrichModelMetadataTask( @RequestParam(name = "model-id", required = true) final UUID modelId, @RequestParam(name = "document-id", required = false) final UUID documentId, - @RequestParam(name = "mode", required = false, defaultValue = "ASYNC") final TaskMode mode, + @RequestParam(name = "mode", required = false, defaultValue = "SYNC") final TaskMode mode, @RequestParam(name = "project-id", required = false) final UUID projectId, @RequestParam(name = "overwrite", required = false, defaultValue = "false") final boolean overwrite ) { @@ -765,9 +766,8 @@ public ResponseEntity createEnrichModelMetadataTask( projectId ); - final TaskResponse resp; try { - resp = modelService.enrichModel(projectId, Optional.of(documentId), modelId, permission, true); + modelService.enrichModel(projectId, documentId, modelId, permission, true); } catch (final IOException e) { log.error("An error occurred while trying to retrieve information necessary for model enrichment.", e); throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("postgres.service-unavailable")); @@ -782,7 +782,14 @@ public ResponseEntity createEnrichModelMetadataTask( throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, messages.get("task.gollm.timeout")); } - return ResponseEntity.ok().body(resp); + // check that we have a model to return + final Optional model = modelService.getAsset(modelId, permission); + if (model.isEmpty()) { + log.error(String.format("The model %s does not exist.", modelId)); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, messages.get("model.not-found")); + } + + return ResponseEntity.ok().body(model.get().getId()); } @GetMapping("/enrich-amr") diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java index 351f9e29b8..ee78379e86 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/knowledge/KnowledgeController.java @@ -236,7 +236,7 @@ public ResponseEntity equationsToModel( final Model model = modelService.createAsset(responseAMR, projectId, permission); // enrich the model with the document if (documentId != null) { - modelService.enrichModel(projectId, Optional.of(documentId), model.getId(), permission, true); + modelService.enrichModel(projectId, documentId, model.getId(), permission, true); } return ResponseEntity.ok(model.getId()); } catch (final IOException e) { @@ -258,9 +258,7 @@ public ResponseEntity equationsToModel( } // If a model id is provided, update the existing model - final Optional model; - - model = modelService.getAsset(modelId, permission); + final Optional model = modelService.getAsset(modelId, permission); if (model.isEmpty()) { log.error(String.format("The model id %s does not exist.", modelId)); throw new ResponseStatusException(HttpStatus.BAD_REQUEST, messages.get("model.not-found")); @@ -271,7 +269,7 @@ public ResponseEntity equationsToModel( modelService.updateAsset(responseAMR, projectId, permission); // enrich the model with the document if (documentId != null) { - modelService.enrichModel(projectId, Optional.of(documentId), responseAMR.getId(), permission, true); + modelService.enrichModel(projectId, documentId, responseAMR.getId(), permission, true); } return ResponseEntity.ok(model.get().getId()); } catch (final IOException e) { diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java index 8b5d428947..35780f3bd6 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java @@ -4,10 +4,11 @@ import java.util.Optional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.NoRepositoryBean; @NoRepositoryBean -public interface PSCrudSoftDeleteRepository extends PSCrudRepository { +public interface PSCrudSoftDeleteRepository extends JpaRepository { List findAllByIdInAndDeletedOnIsNull(final List ids); Optional getByIdAndDeletedOnIsNull(final ID id); diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java index f03237021f..1d1425e70d 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/ModelService.java @@ -5,6 +5,8 @@ import co.elastic.clients.elasticsearch.core.search.SourceFilter; import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.observation.annotation.Observed; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; import java.io.IOException; import java.util.List; import java.util.Optional; @@ -262,23 +264,18 @@ public Optional updateAsset( return updatedOptional; } - public TaskResponse enrichModel( + public UUID enrichModel( final UUID projectId, - final Optional documentId, + final UUID documentId, final UUID modelId, final Schema.Permission permission, final boolean overwrite ) throws IOException, ExecutionException, InterruptedException, TimeoutException { - // Grab the document - final Optional document = documentAssetService.getAsset(documentId.get(), permission); - if (document.isEmpty()) { - String errorString = String.format("Document %s not found", documentId); - log.warn(errorString); - throw new IOException(errorString); - } + // Grab the document if it exists + final Optional document = documentAssetService.getAsset(documentId, permission); // make sure there is text in the document - if (document.get().getText() == null || document.get().getText().isEmpty()) { + if (document.isPresent() && (document.get().getText() == null || document.get().getText().isEmpty())) { String errorString = String.format("Document %s has no extracted text", documentId); log.warn(errorString); throw new IOException(errorString); @@ -294,7 +291,7 @@ public TaskResponse enrichModel( // stripping the metadata from the model before its sent since it can cause // gollm to fail with massive inputs - model.get().setMetadata(null); + model.get().setMetadata(new ModelMetadata()); final TaskRequest req; @@ -323,78 +320,78 @@ public TaskResponse enrichModel( final TaskResponse resp = taskService.runTask(TaskService.TaskMode.SYNC, req); // at this point the initial enrichment has happened. - model = getAsset(modelId, permission); - if (model.isEmpty()) { + final Optional newModel = getAsset(modelId, permission); + if (newModel.isEmpty()) { String errorString = String.format("Model %s not found", modelId); log.warn(errorString); throw new IOException(errorString); } // Update State Grounding - if (model.get().isRegnet()) { - List vertices = model.get().getVerticies(); + if (newModel.get().isRegnet()) { + List vertices = newModel.get().getVerticies(); vertices.forEach(vertex -> { if (vertex == null) { vertex = new RegNetVertex(); } TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, vertex); }); - model.get().setVerticies(vertices); + newModel.get().setVerticies(vertices); } else { - List states = model.get().getStates(); + List states = newModel.get().getStates(); states.forEach(state -> { if (state == null) { state = new State(); } TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, state); }); - model.get().setStates(states); + newModel.get().setStates(states); } //Update Observable Grounding - if (model.get().getObservables() != null && !model.get().getObservables().isEmpty()) { - List observables = model.get().getObservables(); + if (newModel.get().getObservables() != null && !newModel.get().getObservables().isEmpty()) { + List observables = newModel.get().getObservables(); observables.forEach(observable -> { if (observable == null) { observable = new Observable(); } TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, observable); }); - model.get().setObservables(observables); + newModel.get().setObservables(observables); } //Update Parameter Grounding - if (model.get().getParameters() != null && !model.get().getParameters().isEmpty()) { - List parameters = model.get().getParameters(); + if (newModel.get().getParameters() != null && !newModel.get().getParameters().isEmpty()) { + List parameters = newModel.get().getParameters(); parameters.forEach(parameter -> { if (parameter == null) { parameter = new ModelParameter(); } TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, parameter); }); - model.get().setParameters(parameters); + newModel.get().setParameters(parameters); } //Update Transition Grounding - if (model.get().getTransitions() != null && !model.get().getTransitions().isEmpty()) { - List transitions = model.get().getTransitions(); + if (newModel.get().getTransitions() != null && !newModel.get().getTransitions().isEmpty()) { + List transitions = newModel.get().getTransitions(); transitions.forEach(transition -> { if (transition == null) { transition = new Transition(); } TaskUtilities.performDKGSearchAndSetGrounding(miraProxy, transition); }); - model.get().setTransitions(transitions); + newModel.get().setTransitions(transitions); } try { - updateAsset(model.get(), projectId, permission); + updateAsset(newModel.get(), projectId, permission); } catch (IOException e) { String errorString = String.format("Failed to update model %s", modelId); log.warn(errorString); throw new IOException(errorString); } - return resp; + return newModel.get().getId(); } } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetServiceWithoutSearch.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetServiceWithoutSearch.java index 9e73755ad7..01f4eb84bd 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetServiceWithoutSearch.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/TerariumAssetServiceWithoutSearch.java @@ -125,7 +125,7 @@ public Optional deleteAsset(final UUID id, final UUID projectId, final Schema return Optional.empty(); } asset.get().setDeletedOn(Timestamp.from(Instant.now())); - repository.save(asset.get()); + repository.saveAndFlush(asset.get()); return asset; } @@ -146,7 +146,7 @@ public T createAsset(final T asset, final UUID projectId, final Schema.Permissio asset.setPublicAsset(projectService.isProjectPublic(projectId)); - return repository.save(asset); + return repository.saveAndFlush(asset); } /** @@ -169,7 +169,7 @@ public List createAssets(final List assets, final UUID projectId, final Sc final boolean projectIsPublic = projectService.isProjectPublic(projectId); assets.forEach(asset -> asset.setPublicAsset(projectIsPublic)); - return repository.saveAll(assets); + return repository.saveAllAndFlush(assets); } /** @@ -198,7 +198,7 @@ public Optional updateAsset(final T asset, final UUID projectId, final Schema asset.setPublicAsset(projectService.isProjectPublic(projectId)); - final T updated = repository.save(asset); + final T updated = repository.saveAndFlush(asset); // Update the related ProjectAsset projectAssetService.updateByAsset(updated, hasWritePermission); diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java index 4e2d592995..0a7ecec295 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/TaskUtilities.java @@ -75,6 +75,8 @@ public static TaskRequest getModelCardTask(String userId, DocumentAsset document } catch (JsonProcessingException e) { throw new IOException("Unable to serialize document text"); } + } else { + input.setResearchPaper(""); } // Create the task diff --git a/packages/server/src/main/resources/application.properties b/packages/server/src/main/resources/application.properties index 4ca8ea0b38..9e35194d7c 100644 --- a/packages/server/src/main/resources/application.properties +++ b/packages/server/src/main/resources/application.properties @@ -1,14 +1,15 @@ ######################################################################################################################## # Database configuration ######################################################################################################################## -spring.datasource.url=jdbc:postgresql://10.64.22.49:5432/terarium +spring.datasource.hikari.maximum-pool-size=64 +spring.datasource.initialize=false spring.datasource.password=${terarium.db.password} +spring.datasource.url=jdbc:postgresql://10.64.22.49:5432/terarium spring.datasource.username=${terarium.db.username} -spring.datasource.initialize=false -spring.jpa.hibernate.ddl-auto=none -spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect spring.flyway.enabled=false -spring.datasource.hikari.maximum-pool-size=64 +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.hibernate.ddl-auto=none +spring.jpa.open-in-view=false ######################################################################################################################## # Elasticsearch configuration From b2843f8a93ab9e792db6e1a403e0f2f381d8239e Mon Sep 17 00:00:00 2001 From: David Gauldie Date: Tue, 5 Nov 2024 11:28:50 -0500 Subject: [PATCH 4/4] remove model card notifications --- .../src/components/model/tera-model.vue | 15 +-------------- .../navbar/tera-notification-panel.vue | 1 - .../widgets/tera-asset-enrichment.vue | 17 ++--------------- .../src/services/notificationEventHandlers.ts | 9 --------- .../data/TerariumAssetServiceWithoutSearch.java | 8 ++++---- 5 files changed, 7 insertions(+), 43 deletions(-) diff --git a/packages/client/hmi-client/src/components/model/tera-model.vue b/packages/client/hmi-client/src/components/model/tera-model.vue index 7a6c978541..dec6482ac5 100644 --- a/packages/client/hmi-client/src/components/model/tera-model.vue +++ b/packages/client/hmi-client/src/components/model/tera-model.vue @@ -92,8 +92,7 @@ import TeraModelParts from '@/components/model/tera-model-parts.vue'; import TeraSaveAssetModal from '@/components/project/tera-save-asset-modal.vue'; import { getModel, updateModel } from '@/services/model'; import type { FeatureConfig } from '@/types/common'; -import { AssetType, ClientEvent, ClientEventType, type Model, TaskResponse, TaskStatus } from '@/types/Types'; -import { useClientEvent } from '@/composables/useClientEvent'; +import { AssetType, type Model } from '@/types/Types'; import { useProjects } from '@/composables/project'; import { logger } from '@/utils/logger'; @@ -118,18 +117,6 @@ const props = defineProps({ const emit = defineEmits(['close-preview', 'on-save']); -// Listen for the task completion event -useClientEvent(ClientEventType.TaskGollmModelCard, (event: ClientEvent) => { - if ( - !event.data || - event.data.status !== TaskStatus.Success || - event.data.additionalProperties.modelId !== props.assetId - ) { - return; - } - fetchModel(); -}); - const model = ref(null); const temporaryModel = ref(null); diff --git a/packages/client/hmi-client/src/components/navbar/tera-notification-panel.vue b/packages/client/hmi-client/src/components/navbar/tera-notification-panel.vue index a6427231d3..81001e71a2 100644 --- a/packages/client/hmi-client/src/components/navbar/tera-notification-panel.vue +++ b/packages/client/hmi-client/src/components/navbar/tera-notification-panel.vue @@ -126,7 +126,6 @@ const cancelTask = (item: NotificationItem) => { if (!item.supportCancel) return; if ( [ - ClientEventType.TaskGollmModelCard, ClientEventType.TaskGollmConfigureModelFromDocument, ClientEventType.TaskGollmConfigureModelFromDataset, ClientEventType.TaskGollmCompareModel diff --git a/packages/client/hmi-client/src/components/widgets/tera-asset-enrichment.vue b/packages/client/hmi-client/src/components/widgets/tera-asset-enrichment.vue index 8339d8876e..86b72649fe 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-asset-enrichment.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-asset-enrichment.vue @@ -39,8 +39,8 @@