Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/client/hmi-client/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
3
<template>
<!-- Sets the Toast notification groups and their respective levels-->
<Toast position="top-right" group="error" />
<Toast position="top-right" group="warn" />
<Toast position="top-right" group="info" />
<Toast position="top-right" group="success" />
<Toast position="top-center" group="error" />
<Toast position="top-center" group="warn" />
<Toast position="top-center" group="info" />
<Toast position="top-center" group="success" />
<header>
<tera-navbar :active="displayNavBar" />
</header>
Expand All @@ -22,7 +23,7 @@
import { computed, onMounted, watch } from 'vue';
import Toast from 'primevue/toast';

import { ToastSummaries, ToastSeverity, useToastService } from '@/services/toast';
import { ToastSeverity, ToastSummaries, useToastService } from '@/services/toast';
import { useRoute, useRouter } from 'vue-router';
import API from '@/api/api';
import TeraNavbar from '@/components/navbar/tera-navbar.vue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.p-toast {
opacity: $toastOpacity;
width: 40rem;

.p-toast-message {
margin: $toastMargin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const updateLatexFormula = (equationsList: string[]) => {
const updateModelFromEquations = async () => {
isUpdating.value = true;
isEditing.value = false;
const updated = await equationsToAMR('latex', equations.value, 'petrinet', props.model.id);
if (updated) {
const modelId = await equationsToAMR(equations.value, 'petrinet', props.model.id);
if (modelId) {
emit('model-updated');
useToastService().success('Success', `Model Updated from equation`);
}
Expand All @@ -87,7 +87,6 @@ const updateModelFromEquations = async () => {
watch(
() => props.model,
async () => {
// const latexFormula = await petriToLatex(convertAMRToACSet(props.model));
const latexFormula = await getModelEquation(props.model);
if (latexFormula) {
updateLatexFormula(cleanLatexEquations(latexFormula.split(' \\\\')));
Expand Down
27 changes: 8 additions & 19 deletions packages/client/hmi-client/src/services/knowledge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import API, { Poller, PollerResult, PollerState, PollResponse } from '@/api/api';
import { AxiosError, AxiosResponse } from 'axios';
import type { Code, Dataset, ExtractionResponse, Model } from '@/types/Types';
import type { Code, Dataset, Model } from '@/types/Types';
import { logger } from '@/utils/logger';
import { modelCard } from './goLLM';

Expand Down Expand Up @@ -46,28 +46,17 @@ export async function fetchExtraction(id: string): Promise<PollerResult<any>> {
* @return {Promise<any>}
*/
export const equationsToAMR = async (
format: string,
equations: string[],
framework: string = 'petrinet',
modelId?: string
): Promise<any> => {
): Promise<string | null> => {
try {
const response: AxiosResponse<ExtractionResponse> = await API.post(
`/knowledge/equations-to-model`,
{ format, framework, modelId, equations }
);
if (response && response?.status === 200) {
const { id, status } = response.data;
if (status === 'queued') {
const result = await fetchExtraction(id);
if (result?.state === PollerState.Done && result?.data?.job_result?.status_code === 200) {
return result.data;
}
}
if (status === 'finished' && response.data.result.job_result?.status_code === 200) {
return response.data.result;
}
}
const response: AxiosResponse<string> = await API.post(`/knowledge/equations-to-model`, {
model: framework,
modelId,
equations
});
return response.data;
} catch (error: unknown) {
logger.error(error, { showToast: false });
}
Expand Down
11 changes: 6 additions & 5 deletions packages/client/hmi-client/src/services/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export async function generateModelCard(
}
}

// helper fucntion to get the model type, will always default to petrinet if the model is not found
// helper function to get the model type, will always default to petrinet if the model is not found
export function getModelType(model: Model | null | undefined): AMRSchemaNames {
const schemaName = model?.header?.schema_name?.toLowerCase();
if (schemaName === 'regnet') {
Expand All @@ -194,15 +194,16 @@ export function getModelType(model: Model | null | undefined): AMRSchemaNames {
}

// Converts a model into latex equation, either one of petrinet, stocknflow, or regnet;
export async function getModelEquation(model: Model) {
export async function getModelEquation(model: Model): Promise<string> {
const unSupportedFormats = ['decapodes'];
if (unSupportedFormats.includes(model.header.schema_name as string)) {
console.log(`getModelEquation: ${model.header.schema_name} not suported `);
console.warn(`getModelEquation: ${model.header.schema_name} not supported `);
return '';
}

const id = model.id;
const response = await API.get(`/transforms/model-to-latex/${id}`);
// TODO - replace the get with the POST when the backend is ready, see PR https://github.com/DARPA-ASKEM/sciml-service/pull/167
const response = await API.get(`/transforms/model-to-latex/${model.id}`);
// const response = await API.post(`/transforms/model-to-latex/`, model);
const latex = response.data.latex;
if (!latex) return '';

Expand Down
2 changes: 0 additions & 2 deletions packages/client/hmi-client/src/services/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const DEFAULT_DURATION = 3000; // 3 seconds
// TODO: Define more.
export enum ToastSummaries {
NETWORK_ERROR = 'Network Error',
UNKNOWN_ERROR = 'Unknown Error',
SERVICE_UNAVAILABLE = 'Service Unavailable',
ATTENTION = 'Attention',
INFO = 'Info',
WARNING = 'Warning',
ERROR = 'Error',
Expand Down
17 changes: 16 additions & 1 deletion packages/client/hmi-client/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ function highlightText(text: string, searchTerms: string): string {
return text.replace(search, (match) => emphasis(match));
}

export { highlightText as highlight };
/**
* Convert a pascal case string to a capital sentence, avoids acronyms.
* Most useful for converting enum of model framework to human-readable string:
* - "GeneralizedAMR" -> "Generalized AMR"
* - "MathExpressionTree" -> "Math Expression Tree"
* @param pascalCaseString
*/
function pascalCaseToCapitalSentence(pascalCaseString) {
// Split the string by capital letters, but avoid acronyms
const words = pascalCaseString.match(/([A-Z]+[a-z]*)/g);

// Capitalize the first letter of each word and join them with spaces
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
}

export { highlightText as highlight, pascalCaseToCapitalSentence };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ModelFromEquationsOperation as operation } from './model-from-equations-operation';
import node from './tera-model-from-equations-node.vue';
import drilldown from './tera-model-from-equations-drilldown.vue';

const name = operation.name;

export { name, operation, node, drilldown };
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export function instanceOfEquationFromImageBlock(
return 'fileName' in object;
}

export interface ModelFromDocumentState {
export interface ModelFromEquationsState {
equations: AssetBlock<EquationBlock | EquationFromImageBlock>[];
text: string;
modelFramework: string;
modelId: string | null;
modelService: ModelServiceType;
}

export const ModelFromDocumentOperation: Operation = {
export const ModelFromEquationsOperation: Operation = {
name: WorkflowOperationTypes.MODEL_FROM_DOCUMENT,
description: 'Create model from equations',
displayName: 'Create model from equations',
Expand All @@ -35,7 +35,7 @@ export const ModelFromDocumentOperation: Operation = {
action: () => {},

initState: () => {
const init: ModelFromDocumentState = {
const init: ModelFromEquationsState = {
equations: [],
text: '',
modelFramework: 'petrinet',
Expand Down
Loading