From b8ce1ee8ed67f95a86fc699cca43e83ad3699940 Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Tue, 3 Dec 2024 12:43:50 -0500 Subject: [PATCH 1/5] add extractionService option to use MIRA --- .../knowledge/KnowledgeController.java | 64 +++++++++++++------ 1 file changed, 46 insertions(+), 18 deletions(-) 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 119ce0de04..ce2e4eac67 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 @@ -76,6 +76,7 @@ import software.uncharted.terarium.hmiserver.service.data.ProvenanceSearchService; import software.uncharted.terarium.hmiserver.service.data.ProvenanceService; import software.uncharted.terarium.hmiserver.service.tasks.EquationsCleanupResponseHandler; +import software.uncharted.terarium.hmiserver.service.tasks.LatexToAMRResponseHandler; import software.uncharted.terarium.hmiserver.service.tasks.TaskService; import software.uncharted.terarium.hmiserver.service.tasks.TaskService.TaskMode; import software.uncharted.terarium.hmiserver.utils.ByteMultipartFile; @@ -213,25 +214,52 @@ public ResponseEntity equationsToModel( } } - // Get an AMR from Skema Unified Service - try { - responseAMR = skemaUnifiedProxy.consolidatedEquationsToAMR(req).getBody(); - if (responseAMR == null) { - log.warn("Skema Unified Service did not return a valid AMR based on the provided equations"); - throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("skema.bad-equations")); + // Get an AMR from Skema Unified Service or MIRA + String extractionService = "mira"; + if (req.get("extractionService") != null) { + extractionService = req.get("extractionService").asText(); + } + + if (extractionService == "mira") { + final TaskRequest taskReq = new TaskRequest(); + final String latex = req.get("equations").toString(); + + taskReq.setType(TaskType.MIRA); + try { + taskReq.setInput(latex.getBytes()); + taskReq.setScript(LatexToAMRResponseHandler.NAME); + taskReq.setUserId(currentUserService.get().getId()); + final TaskResponse taskResp = taskService.runTaskSync(taskReq); + final JsonNode taskResponseJSON = mapper.readValue(taskResp.getOutput(), JsonNode.class); + final String amrString = taskResponseJSON.get("response").asText(); + ObjectNode objNode = (ObjectNode) mapper.readTree(amrString); + + final JsonNode testNode = mapper.readValue(amrString, JsonNode.class); + responseAMR = mapper.convertValue(testNode, Model.class); + } catch (Exception e) { + e.printStackTrace(); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "failed to convert latex equations to AMR"); + } + } else { + try { + responseAMR = skemaUnifiedProxy.consolidatedEquationsToAMR(req).getBody(); + if (responseAMR == null) { + log.warn("Skema Unified Service did not return a valid AMR based on the provided equations"); + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, messages.get("skema.bad-equations")); + } + } catch (final FeignException e) { + log.error( + "An exception occurred while Skema Unified Service was trying to produce an AMR based on the provided equations", + e + ); + throw handleSkemaFeignException(e); + } catch (final Exception e) { + log.error( + "An unhandled error occurred while Skema Unified Service was trying to produce an AMR based on the provided equations", + e + ); + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("skema.internal-error")); } - } catch (final FeignException e) { - log.error( - "An exception occurred while Skema Unified Service was trying to produce an AMR based on the provided equations", - e - ); - throw handleSkemaFeignException(e); - } catch (final Exception e) { - log.error( - "An unhandled error occurred while Skema Unified Service was trying to produce an AMR based on the provided equations", - e - ); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("skema.internal-error")); } if (!responseAMR.isPetrinet()) { From 6dd0fed78a23f2b2cb591395ff11c16372fff515 Mon Sep 17 00:00:00 2001 From: Cole Blanchard Date: Tue, 3 Dec 2024 13:46:11 -0500 Subject: [PATCH 2/5] hook up skema/mira button to backend --- .../tera-model-from-equations-drilldown.vue | 38 ++++++++++++++++--- .../hmi-client/src/services/knowledge.ts | 6 ++- .../knowledge/KnowledgeController.java | 3 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue index ae93cc4f81..589fd1e4f6 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue @@ -28,11 +28,11 @@ Specify which equations to use for this model.
@@ -198,6 +198,7 @@ import TeraDrilldownSection from '@/components/drilldown/tera-drilldown-section. import TeraPdfEmbed from '@/components/widgets/tera-pdf-embed.vue'; import TeraTextEditor from '@/components/documents/tera-text-editor.vue'; import { logger } from '@/utils/logger'; +import SplitButton from 'primevue/splitbutton'; import { ModelFromEquationsState, EquationBlock } from './model-from-equations-operation'; const emit = defineEmits(['close', 'update-state', 'append-output', 'update-output', 'select-output']); @@ -207,6 +208,17 @@ const props = defineProps<{ const selectedOutputId = ref(''); +const runItems = [ + { + label: 'SKEMA', + command: () => onRun('skema') + }, + { + label: 'Mira', + command: () => onRun('mira') + } +]; + const clonedState = ref({ equations: [], text: '', @@ -366,7 +378,7 @@ function onCheckBoxChange(equation) { emit('update-state', state); } -async function onRun() { +async function onRun(extractionService: string = 'skema') { isOutputOpen.value = true; isModelLoading.value = true; const equationsText = clonedState.value.equations @@ -382,7 +394,8 @@ async function onRun() { const request: EquationsToAMRRequest = { equations: cleanedEquations, framework: clonedState.value.modelFramework, - documentId: document.value?.id + documentId: document.value?.id, + extractionService }; const modelId = await equationsToAMR(request); // If there isn't a modelId returned at least show the cleaned equations @@ -589,4 +602,17 @@ watch( .p-panel:deep(.p-panel-footer) { display: none; } + +:deep(.p-splitbutton .p-button:first-of-type) { + border-top-right-radius: 0; + border-bottom-right-radius: 0; + border-right: 0 none; + pointer-events: none; +} + +:deep(.p-splitbutton .p-button:last-of-type) { + border-top-left-radius: 0; + border-bottom-left-radius: 0; + color: #fff; +} diff --git a/packages/client/hmi-client/src/services/knowledge.ts b/packages/client/hmi-client/src/services/knowledge.ts index 2fed9edddf..59b437533a 100644 --- a/packages/client/hmi-client/src/services/knowledge.ts +++ b/packages/client/hmi-client/src/services/knowledge.ts @@ -17,6 +17,7 @@ export interface EquationsToAMRRequest { framework?: string; modelId?: Model['id']; documentId?: DocumentAsset['id']; + extractionService?: string; } /** @@ -45,13 +46,14 @@ export const getCleanedEquations = async ( * @return {Promise} */ export const equationsToAMR = async (request: EquationsToAMRRequest): Promise => { - const { equations, framework: model = 'petrinet', modelId, documentId } = request; + const { equations, framework: model = 'petrinet', modelId, documentId, extractionService } = request; try { const response: AxiosResponse = await API.post(`/knowledge/equations-to-model`, { model, modelId, documentId, - equations + equations, + extractionService }); return response.data; } catch (error: unknown) { 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 ce2e4eac67..b996e3b06e 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 @@ -220,10 +220,9 @@ public ResponseEntity equationsToModel( extractionService = req.get("extractionService").asText(); } - if (extractionService == "mira") { + if (extractionService.equals("mira")) { final TaskRequest taskReq = new TaskRequest(); final String latex = req.get("equations").toString(); - taskReq.setType(TaskType.MIRA); try { taskReq.setInput(latex.getBytes()); From 2322f8498e4d3f7a586b388c4659917d6ff193ba Mon Sep 17 00:00:00 2001 From: Cole Blanchard Date: Tue, 3 Dec 2024 14:12:50 -0500 Subject: [PATCH 3/5] more merging --- .../tera-model-from-equations-drilldown.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue index 5c6d0ca2ac..3022db9d40 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue @@ -377,7 +377,7 @@ function onCheckBoxChange(equation) { emit('update-state', state); } -async function onRun(extractionService: string = 'skema') { +async function onRun(extractionService: 'mira' | 'skema' = 'skema') { isOutputOpen.value = true; isModelLoading.value = true; const equationsText = clonedState.value.equations @@ -392,7 +392,6 @@ async function onRun(extractionService: string = 'skema') { const request: EquationsToAMRRequest = { equations: cleanedEquations, - framework: clonedState.value.modelFramework, documentId: document.value?.id, workflowId: props.node.workflowId, nodeId: props.node.id, From 0292b050f18796725e441213d2089310b50f06cc Mon Sep 17 00:00:00 2001 From: Cole Blanchard Date: Tue, 3 Dec 2024 16:11:46 -0500 Subject: [PATCH 4/5] notification service --- .../src/services/notificationEventHandlers.ts | 12 ++++++------ packages/client/hmi-client/src/types/common.ts | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/client/hmi-client/src/services/notificationEventHandlers.ts b/packages/client/hmi-client/src/services/notificationEventHandlers.ts index 5470f396f3..7a8cd54c56 100644 --- a/packages/client/hmi-client/src/services/notificationEventHandlers.ts +++ b/packages/client/hmi-client/src/services/notificationEventHandlers.ts @@ -2,6 +2,7 @@ import { useProjects } from '@/composables/project'; import { CloneProjectStatusUpdate, ExtractionStatusUpdate, + ModelEnrichmentStatusUpdate, NotificationItem, NotificationItemStatus } from '@/types/common'; @@ -205,14 +206,13 @@ export const createNotificationEventHandlers = (notificationItems: Ref(ClientEventType.KnowledgeEnrichmentModel, (event, created) => { + registerHandler(ClientEventType.KnowledgeEnrichmentModel, (event, created) => { created.sourceName = 'Model Enrichment'; - // Check if the event data contains a workflowId and nodeId - if (event.data.additionalProperties.workflowId && event.data.additionalProperties.nodeId) { - created.assetId = event.data.additionalProperties.workflowId as string; + if (event.data.data?.workflowId && event.data.data?.nodeId) { + created.assetId = event.data.data.workflowId as string; created.pageType = AssetType.Workflow; - created.nodeId = event.data.additionalProperties.nodeId as string; + created.nodeId = event.data.data.nodeId as string; getWorkflow(created.assetId, created.projectId).then((workflow) => Object.assign(created, { context: workflow?.name || '' }) ); @@ -220,7 +220,7 @@ export const createNotificationEventHandlers = (notificationItems: Ref diff --git a/packages/client/hmi-client/src/types/common.ts b/packages/client/hmi-client/src/types/common.ts index 8589ad7638..365a2b27f0 100644 --- a/packages/client/hmi-client/src/types/common.ts +++ b/packages/client/hmi-client/src/types/common.ts @@ -158,6 +158,8 @@ interface Comparison { conclusion: string; } +export type ModelEnrichmentStatusUpdate = StatusUpdate<{ modelId: string; workflowId: string; nodeId: string }>; + export type ExtractionStatusUpdate = StatusUpdate<{ documentId: string }>; export type CloneProjectStatusUpdate = StatusUpdate<{ projectId: string }>; export interface NotificationItem extends NotificationItemStatus, AssetRoute { From 13443717e51d8330c150e704615dfe52706e2d44 Mon Sep 17 00:00:00 2001 From: Cole Blanchard Date: Tue, 3 Dec 2024 16:44:02 -0500 Subject: [PATCH 5/5] error msg --- .../hmiserver/controller/knowledge/KnowledgeController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 553d23265e..77115797c9 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 @@ -284,7 +284,7 @@ public ResponseEntity equationsToModel( final JsonNode testNode = mapper.readValue(amrString, JsonNode.class); responseAMR = mapper.convertValue(testNode, Model.class); } catch (Exception e) { - e.printStackTrace(); + log.error("failed to convert latex equations to AMR", e); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "failed to convert latex equations to AMR"); } } else {