Skip to content

Commit

Permalink
display gollm extractions (#3199)
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis authored Mar 28, 2024
1 parent ac2062a commit 176b913
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 29 deletions.
4 changes: 3 additions & 1 deletion packages/client/hmi-client/src/services/goLLM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export async function configureModelFromDocument(
const taskId = response.data.id;
return await handleTaskById(taskId, handlers);
} catch (err) {
logger.error(`An issue occured while exctracting a model configuration from document. ${err}`);
const message = `An issue occurred while extracting a model configuration from document. ${err}`;
logger.error(message);
console.debug(message);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
@update:selection="onSelection"
/>
</template>

<section :tabName="ConfigTabs.Wizard">
<tera-drilldown-section class="pl-3 pr-3 gap-0">
<!-- Suggested configurations -->
<div class="box-container mt-3" v-if="model">
<Accordion multiple :active-index="[0]">
<AccordionTab>
Expand All @@ -24,16 +24,15 @@
>({{ suggestedConfirgurationContext.tableData.length }})</span
>
<Button
class="ml-auto"
icon="pi pi-sign-out"
label="Extract configurations from inputs"
outlined
severity="secondary"
@click.stop="extractConfigurationsFromInputs"
style="margin-left: auto"
:loading="isLoading"
@click.stop="extractConfigurationsFromInputs"
/>
</template>

<DataTable
:value="suggestedConfirgurationContext.tableData"
size="small"
Expand All @@ -49,15 +48,15 @@
<Button :label="data.name" text @click="onOpenSuggestedConfiguration(data)" />
</template>
</Column>
<Column field="description" header="Description" style="width: 30%"></Column>
<Column field="description" header="Description" style="width: 30%" />
<Column field="createdOn" header="Created On" :sortable="true" style="width: 25%">
<template #body="{ data }">
{{ formatTimestamp(data.createdOn) }}
{{ formatTimestamp(data?.createdOn) }}
</template>
</Column>
<Column header="Source" style="width: 30%">
<template #body="{ data }">
{{ data.configuration.metadata?.source?.join(',') || '--' }}
{{ data?.configuration.metadata?.source?.join(',') || '--' }}
</template>
</Column>
<Column style="width: 7rem">
Expand Down Expand Up @@ -105,9 +104,7 @@
<AccordionTab header="Diagram">
<tera-model-diagram v-if="model" :model="model" :is-editable="false" />
</AccordionTab>
<template
v-if="modelType === AMRSchemaNames.PETRINET || modelType === AMRSchemaNames.STOCKFLOW"
>
<template v-if="isPetriNet || isStockFlow">
<AccordionTab>
<template #header>
Initial variable values<span class="artifact-amount">({{ numInitials }})</span>
Expand All @@ -127,7 +124,7 @@
/>
</AccordionTab>
</template>
<template v-else-if="modelType === AMRSchemaNames.REGNET">
<template v-else-if="isRegNet">
<AccordionTab header="Vertices">
<DataTable v-if="!isEmpty(vertices)" data-key="id" :value="vertices">
<Column field="id" header="Symbol" />
Expand Down Expand Up @@ -174,7 +171,7 @@
</AccordionTab>
</Accordion>

<!-- For Nelson eval debug -->
<!-- TODO - For Nelson eval debug, remove in April 2024 -->
<div style="padding-left: 1rem; font-size: 90%; color: #555555">
<div>Model config id: {{ selectedConfigId }}</div>
<div>Model id: {{ props.node.inputs[0].value?.[0] }}</div>
Expand Down Expand Up @@ -288,7 +285,7 @@
</Teleport>

<!-- Matrix effect easter egg -->
<canvas id="matrix-canvas"></canvas>
<canvas id="matrix-canvas" />
</template>

<script setup lang="ts">
Expand Down Expand Up @@ -489,8 +486,13 @@ const initializeEditor = (editorInstance: any) => {
};
const extractConfigurationsFromInputs = async () => {
if (!model.value?.id) return;
console.group('Extracting configurations from inputs');
if (!model.value?.id) {
console.debug('Model not loaded yet, try later.');
return;
}
if (documentId.value) {
console.debug('Configuring model from document', documentId.value);
modelFromDocumentHandler.value = await configureModelFromDocument(
documentId.value,
model.value.id,
Expand All @@ -502,6 +504,8 @@ const extractConfigurationsFromInputs = async () => {
}
if (data.status === TaskStatus.Success) {
logger.success('Model configured from document');
const outputJSON = JSON.parse(new TextDecoder().decode(data.output));
console.debug('Model configured from document', outputJSON);
closeConnection();
}
},
Expand All @@ -514,6 +518,7 @@ const extractConfigurationsFromInputs = async () => {
);
}
if (datasetIds.value) {
console.debug('Configuring model from dataset(s)', datasetIds.value?.toString());
modelFromDatasetHandler.value = await configureModelFromDatasets(
model.value.id,
datasetIds.value,
Expand All @@ -536,6 +541,7 @@ const extractConfigurationsFromInputs = async () => {
}
);
}
console.groupEnd();
};
const handleModelPreview = (data: any) => {
Expand Down Expand Up @@ -600,7 +606,7 @@ const modelConfiguration = computed<ModelConfiguration | null>(() => {
cloneModel.metadata = {};
}
if (modelType.value === AMRSchemaNames.PETRINET || modelType.value === AMRSchemaNames.STOCKFLOW) {
if (isPetriNet.value || isStockFlow) {
if (cloneModel.semantics) {
cloneModel.semantics.ode.initials = knobs.value.initials;
cloneModel.semantics.ode.parameters = knobs.value.parameters;
Expand All @@ -609,7 +615,7 @@ const modelConfiguration = computed<ModelConfiguration | null>(() => {
cloneModel.metadata.parameters = knobs.value.parametersMetadata;
}
modelConfig.configuration = cloneModel;
} else if (modelType.value === AMRSchemaNames.REGNET) {
} else if (isRegNet.value) {
cloneModel.model.parameters = knobs.value.parameters;
cloneModel.metadata.timeseries = knobs.value.timeseries;
cloneModel.metadata.initials = knobs.value.initialsMetadata;
Expand All @@ -631,6 +637,9 @@ const numInitials = computed(() => {
});
const modelType = computed(() => getModelType(model.value));
const isRegNet = computed(() => modelType.value === AMRSchemaNames.REGNET);
const isPetriNet = computed(() => modelType.value === AMRSchemaNames.PETRINET);
const isStockFlow = computed(() => modelType.value === AMRSchemaNames.STOCKFLOW);
const updateConfigParam = (params: ModelParameter[]) => {
for (let i = 0; i < knobs.value.parameters.length; i++) {
Expand All @@ -651,10 +660,10 @@ const updateConfigInitial = (inits: Initial[]) => {
};
const updateConfigFromModel = (inputModel: Model) => {
if (modelType.value === AMRSchemaNames.PETRINET || modelType.value === AMRSchemaNames.STOCKFLOW) {
if (isPetriNet.value || isStockFlow) {
knobs.value.initials = inputModel.semantics?.ode.initials ?? [];
knobs.value.parameters = inputModel.semantics?.ode.parameters ?? [];
} else if (modelType.value === AMRSchemaNames.REGNET) {
} else if (isRegNet.value) {
knobs.value.parameters = inputModel.model?.parameters ?? [];
}
knobs.value.timeseries = inputModel.metadata?.timeseries ?? {};
Expand All @@ -671,7 +680,7 @@ const runSanityCheck = () => {
}
let parameters: ModelParameter[] = [];
if ([AMRSchemaNames.PETRINET, AMRSchemaNames.STOCKFLOW].includes(modelType.value)) {
if (isPetriNet.value || isStockFlow) {
if (modelToCheck.semantics?.ode?.parameters) {
parameters = modelToCheck.semantics?.ode?.parameters;
}
Expand Down Expand Up @@ -780,12 +789,9 @@ const initialize = async () => {
// Grab these values from model to inialize them
const ode = model.value?.semantics?.ode;
knobs.value.initials = ode?.initials !== undefined ? ode?.initials : [];
if (
modelType.value === AMRSchemaNames.PETRINET ||
modelType.value === AMRSchemaNames.STOCKFLOW
) {
if (isPetriNet.value || isStockFlow) {
knobs.value.parameters = ode?.parameters !== undefined ? ode?.parameters : [];
} else if (modelType.value === AMRSchemaNames.REGNET) {
} else if (isRegNet.value) {
knobs.value.parameters =
model.value?.model?.parameters !== undefined ? model.value?.model?.parameters : [];
}
Expand Down Expand Up @@ -849,10 +855,10 @@ const useSuggestedConfig = (config: ModelConfiguration) => {
knobs.value.name = config.name;
knobs.value.description = config.description ?? '';
if (modelType.value === AMRSchemaNames.PETRINET || modelType.value === AMRSchemaNames.STOCKFLOW) {
if (isPetriNet.value || isStockFlow) {
knobs.value.initials = amr.semantics.ode.initials;
knobs.value.parameters = amr.semantics.ode.parameters;
} else if (modelType.value === AMRSchemaNames.REGNET) {
} else if (isRegNet.value) {
knobs.value.parameters = amr.model.parameters;
}
knobs.value.timeseries = amr.metadata?.timeseries ?? {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public ResponseEntity<TaskResponse> createCompareModelsTask(
final CompareModelsResponseHandler.Input input = new CompareModelsResponseHandler.Input();
input.setModelCards(modelCards);

// Create the task
// create the task
final TaskRequest req = new TaskRequest();
req.setType(TaskType.GOLLM);
req.setScript(CompareModelsResponseHandler.NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import software.uncharted.terarium.hmiserver.service.data.ModelConfigurationService;
import software.uncharted.terarium.hmiserver.service.data.ModelService;
import software.uncharted.terarium.hmiserver.service.data.ProvenanceService;
import software.uncharted.terarium.hmiserver.utils.GreekDictionary;

@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -65,15 +66,21 @@ public TaskResponse onSuccess(final TaskResponse resp) {
final Properties props = resp.getAdditionalProperties(Properties.class);
final Model model = modelService.getAsset(props.getModelId()).orElseThrow();
final Response configurations = objectMapper.readValue(((TaskResponse) resp).getOutput(), Response.class);

// For each configuration, create a new model configuration with parameters set
for (final JsonNode condition : configurations.response.get("conditions")) {
// Map the parameters values to the model
final Model modelCopy = new Model(model);
final List<ModelParameter> modelParameters = modelCopy.getParameters();
modelParameters.forEach((parameter) -> {
final String parameterId = parameter.getId();
final JsonNode conditionParameters = condition.get("parameters");
conditionParameters.forEach((conditionParameter) -> {
if (parameter.getId().equals(conditionParameter.get("id").asText())) {
// Get the parameter value from the condition
final String id = conditionParameter.get("id").asText();

// Test against the id of the parameter in greek alphabet or english
if (parameterId.equals(id) || parameterId.equals(GreekDictionary.englishToGreek(id))) {
parameter.setValue(conditionParameter.get("value").doubleValue());
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package software.uncharted.terarium.hmiserver.utils;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

/**
* A class to store the Greek alphabet in a BiMap
*
* englishToGreek("beta")); // Output: β
* greekToEnglish("β")); // Output: beta
*/
public class GreekDictionary {
private static BiMap<String, String> englishGreek = HashBiMap.create();
static {
englishGreek.put("alpha", "α");
englishGreek.put("beta", "β");
englishGreek.put("gamma", "γ");
englishGreek.put("delta", "δ");
englishGreek.put("epsilon", "ε");
englishGreek.put("zeta", "ζ");
englishGreek.put("eta", "η");
englishGreek.put("theta", "θ");
englishGreek.put("iota", "ι");
englishGreek.put("kappa", "κ");
englishGreek.put("lambda", "λ");
englishGreek.put("mu", "μ");
englishGreek.put("nu", "ν");
englishGreek.put("xi", "ξ");
englishGreek.put("omicron", "ο");
englishGreek.put("pi", "π");
englishGreek.put("rho", "ρ");
englishGreek.put("sigma", "σ");
englishGreek.put("tau", "τ");
englishGreek.put("upsilon", "υ");
englishGreek.put("phi", "φ");
englishGreek.put("chi", "χ");
englishGreek.put("psi", "ψ");
englishGreek.put("omega", "ω");
}

public static String englishToGreek(String english) {
return englishGreek.get(english);
}
public static String greekToEnglish(String greek) {
return englishGreek.inverse().get(greek);
}
}


0 comments on commit 176b913

Please sign in to comment.