Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tera-model in operators #4987

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@update-state="(state: any) => emit('update-state', state)"
>
<template #sidebar>
<!-- Document Viewer -->
<tera-slider-panel v-model:is-open="isDocViewerOpen" header="Document Viewer" content-width="100%">
<template #content>
<tera-drilldown-section :is-loading="isFetchingPDF">
Expand Down Expand Up @@ -121,19 +122,8 @@
</tera-slider-panel>
<tera-slider-panel v-model:is-open="isOutputOpen" header="Output" content-width="100%">
<template #content>
<header class="flex align-items-center p-3">
<h4>Equation conversions</h4>
<Button
v-if="selectedModel"
label="Save for re-use"
outlined
severity="secondary"
class="ml-auto"
@click="showSaveModelModal = true"
/>
</header>
<tera-drilldown-preview>
<tera-model-description v-if="selectedModel" :model="selectedModel" :generating-card="isGeneratingCard" />
<tera-model v-if="selectedModel" :assetId="selectedModel.id" @on-save="onModelSaveEvent" />
<tera-operator-placeholder v-else :node="node" style="height: 100%" />
</tera-drilldown-preview>
</template>
Expand All @@ -151,50 +141,31 @@
<script setup lang="ts">
import { AssetBlock, WorkflowNode } from '@/types/workflow';
import Checkbox from 'primevue/checkbox';
import Textarea from 'primevue/textarea';
import TeraAssetBlock from '@/components/widgets/tera-asset-block.vue';
import TeraDrilldown from '@/components/drilldown/tera-drilldown.vue';
import TeraDrilldownPreview from '@/components/drilldown/tera-drilldown-preview.vue';
import TeraAssetBlock from '@/components/widgets/tera-asset-block.vue';
import { computed, onMounted, ref, watch } from 'vue';
import { downloadDocumentAsset, getDocumentAsset, getDocumentFileAsText } from '@/services/document-assets';
import type { Card, DocumentAsset, Model } from '@/types/Types';
import { cloneDeep, isEmpty } from 'lodash';
import { equationsToAMR, type EquationsToAMRRequest } from '@/services/knowledge';
import Button from 'primevue/button';
import { downloadDocumentAsset, getDocumentAsset, getDocumentFileAsText } from '@/services/document-assets';
import { modelCard } from '@/services/goLLM';
import { getModel, updateModel } from '@/services/model';
import TeraOperatorPlaceholder from '@/components/operator/tera-operator-placeholder.vue';
import { useProjects } from '@/composables/project';
import TeraMathEditor from '@/components/mathml/tera-math-editor.vue';
import Textarea from 'primevue/textarea';
import TeraInputText from '@/components/widgets/tera-input-text.vue';
import TeraSaveAssetModal from '@/components/project/tera-save-asset-modal.vue';
import TeraModelDescription from '@/components/model/petrinet/tera-model-description.vue';
import { modelCard } from '@/services/goLLM';
import TeraSliderPanel from '@/components/widgets/tera-slider-panel.vue';

import TeraPdfEmbed from '@/components/widgets/tera-pdf-embed.vue';
import TeraTextEditor from '@/components/documents/tera-text-editor.vue';
import TeraDrilldownSection from '@/components/drilldown/tera-drilldown-section.vue';
import { ModelFromEquationsState, EquationBlock } from './model-from-equations-operation';
import { ModelFromEquationsOperation, ModelFromEquationsState, EquationBlock } from './model-from-equations-operation';

const emit = defineEmits(['close', 'update-state', 'append-output', 'select-output']);
const props = defineProps<{
node: WorkflowNode<ModelFromEquationsState>;
}>();

enum ModelFramework {
PetriNet = 'petrinet',
RegNet = 'regnet',
Decapode = 'decapode',
GeneralizedAMR = 'gamr',
MathExpressionTree = 'met'
}

const selectedOutputId = ref<string>('');

const clonedState = ref<ModelFromEquationsState>({
equations: [],
text: '',
modelFramework: ModelFramework.PetriNet,
modelFramework: 'petrinet',
modelId: null
});

Expand Down Expand Up @@ -381,6 +352,19 @@ function getEquationErrorLabel(equation) {
return equation.asset.extractionError ? "Couldn't extract equation" : '';
}

function onModelSaveEvent(event: any) {
const state = cloneDeep(props.node.state);
state.modelId = event.id;
emit('update-state', state);
emit('append-output', {
type: ModelFromEquationsOperation.outputs[0].type,
label: event.header.name,
value: [event.id],
state,
isSelected: false
});
}

// generates the model card and fetches the model when finished
async function generateCard(modelId: string, docId: string) {
isGeneratingCard.value = true;
Expand Down