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

profile model when creating a model from code #2618

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,111 @@
<template>
<tera-grey-card class="details">
<ul>
<li class="multiple">
<span>
<label>Framework</label>
<div class="framework">{{ model?.header?.schema_name }}</div>
</span>
<span>
<label>Model version</label>
<div>{{ model?.header?.model_version }}</div>
</span>
<span>
<label>Date created</label>
<div>{{ model?.metadata?.processed_at ?? card?.date }}</div>
</span>
</li>
<li>
<label>Created by</label>
<div><tera-show-more-text v-if="authors" :text="authors" :lines="2" /></div>
</li>
<li>
<label>Author email</label>
<div>{{ card?.authorEmail }}</div>
</li>
<li>
<label>Institution</label>
<div>
<tera-show-more-text v-if="card?.authorInst" :text="card?.authorInst" :lines="2" />
</div>
</li>
<li class="multiple">
<span>
<label>License</label>
<div>{{ card?.license }}</div>
</span>
<span>
<label>Complexity</label>
<div>{{ card?.complexity }}</div>
</span>
</li>
<li>
<label>Source</label>
<div>{{ model?.metadata?.processed_by }}</div>
</li>
</ul>
</tera-grey-card>
</template>

<script setup lang="ts">
import TeraGreyCard from '@/components/widgets/tera-grey-card.vue';
import { Model } from '@/types/Types';
import { computed } from 'vue';

const props = defineProps<{
model: Model;
}>();

const card = computed(() => {
if (props.model.metadata?.card) {
const cardWithUnknowns = props.model.metadata?.card;
const cardWithUnknownsArr = Object.entries(cardWithUnknowns);

for (let i = 0; i < cardWithUnknownsArr.length; i++) {
const key = cardWithUnknownsArr[i][0];
if (cardWithUnknowns[key] === 'UNKNOWN') {
cardWithUnknowns[key] = null;
}
}
return cardWithUnknowns;
}
return null;
});

const authors = computed(() => {
const authorsArray = props.model?.metadata?.annotations?.authors ?? [];

if (card.value?.authorAuthor) authorsArray.unshift(card.value?.authorAuthor);

return authorsArray.join(', ');
});
</script>

<style scoped>
.details {
> ul {
list-style: none;
padding: 0.5rem 1rem;
display: flex;
flex-direction: column;
gap: var(--gap-small);

& > li.multiple {
display: flex;

& > span {
flex: 1 0 0;
}
}

& > li label {
color: var(--text-color-subdued);
font-size: var(--font-caption);

& + *:empty:before {
content: '--';
}
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,7 @@
</AccordionTab>
</Accordion>
<section class="details-column">
<tera-grey-card class="details">
<ul>
<li class="multiple">
<span>
<label>Framework</label>
<div class="framework">{{ model?.header?.schema_name }}</div>
</span>
<span>
<label>Model version</label>
<div>{{ model?.header?.model_version }}</div>
</span>
<span>
<label>Date created</label>
<div>{{ model?.metadata?.processed_at ?? card?.date }}</div>
</span>
</li>
<li>
<label>Created by</label>
<div><tera-show-more-text v-if="authors" :text="authors" :lines="2" /></div>
</li>
<li>
<label>Author email</label>
<div>{{ card?.authorEmail }}</div>
</li>
<li>
<label>Institution</label>
<div>
<tera-show-more-text v-if="card?.authorInst" :text="card?.authorInst" :lines="2" />
</div>
</li>
<li class="multiple">
<span>
<label>License</label>
<div>{{ card?.license }}</div>
</span>
<span>
<label>Complexity</label>
<div>{{ card?.complexity }}</div>
</span>
</li>
<li>
<label>Source</label>
<div>{{ model?.metadata?.processed_by }}</div>
</li>
</ul>
</tera-grey-card>
<tera-model-card :model="model" />
<tera-related-documents
:documents="documents"
:asset-type="AssetType.Model"
Expand Down Expand Up @@ -147,10 +102,10 @@ import TeraModelDiagram from '@/components/model/petrinet/model-diagrams/tera-mo
import TeraModelEquation from '@/components/model/petrinet/tera-model-equation.vue';
import TeraModelObservable from '@/components/model/petrinet/tera-model-observable.vue';
import { isDataset, isDocument, isModel } from '@/utils/data-util';
import TeraGreyCard from '@/components/widgets/tera-grey-card.vue';
import TeraColumnarPanel from '@/components/widgets/tera-columnar-panel.vue';
import Column from 'primevue/column';
import DataTable from 'primevue/datatable';
import TeraModelCard from './tera-model-card.vue';
import TeraModelSemanticTables from './tera-model-semantic-tables.vue';

const props = defineProps<{
Expand Down Expand Up @@ -206,14 +161,6 @@ const documents = computed(
})) ?? []
);

const authors = computed(() => {
const authorsArray = props.model?.metadata?.annotations?.authors ?? [];

if (card.value?.authorAuthor) authorsArray.unshift(card.value?.authorAuthor);

return authorsArray.join(', ');
});

// Highlight strings based on props.highlight
function highlightSearchTerms(text: string | undefined): string {
if (!!props.highlight && !!text) {
Expand Down Expand Up @@ -269,32 +216,6 @@ function updateConfiguration(updatedConfiguration: ModelConfiguration) {
display: flex;
flex-direction: column;
gap: var(--gap-small);
> .details {
> ul {
list-style: none;
padding: 0.5rem 1rem;
display: flex;
flex-direction: column;
gap: var(--gap-small);

& > li.multiple {
display: flex;

& > span {
flex: 1 0 0;
}
}

& > li label {
color: var(--text-color-subdued);
font-size: var(--font-caption);

& + *:empty:before {
content: '--';
}
}
}
}
}

.framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const ModelFromCodeOperation: Operation = {
description: 'Create model',
displayName: 'Create model from code',
isRunnable: true,
inputs: [{ type: 'codeAssetId', label: 'Code' }],
inputs: [
{ type: 'codeAssetId', label: 'Code' },
{ type: 'documentId', label: 'Text' }
],
outputs: [],
action: () => {},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
>
<section v-if="selectedModel">
<template v-if="selectedOutput?.state?.modelFramework === ModelFramework.Petrinet">
<tera-model-card :model="selectedModel" />
<tera-model-diagram :model="selectedModel" :is-editable="false"></tera-model-diagram>
<tera-model-semantic-tables :model="selectedModel" readonly />
</template>
Expand Down Expand Up @@ -144,10 +145,11 @@ import { useProjects } from '@/composables/project';
import TeraModelSemanticTables from '@/components/model/petrinet/tera-model-semantic-tables.vue';
import TeraOperatorPlaceholder from '@/components/operator/tera-operator-placeholder.vue';
import { getCodeAsset } from '@/services/code';
import { codeBlocksToAmr } from '@/services/knowledge';
import { codeBlocksToAmr, fetchExtraction, profileModel } from '@/services/knowledge';
import { CodeBlock, CodeBlockType, getCodeBlocks } from '@/utils/code-asset';
import TeraAssetBlock from '@/components/widgets/tera-asset-block.vue';
import TeraModelModal from '@/page/project/components/tera-model-modal.vue';
import TeraModelCard from '@/components/model/petrinet/tera-model-card.vue';
import { ModelFromCodeState } from './model-from-code-operation';

const props = defineProps<{
Expand Down Expand Up @@ -176,6 +178,7 @@ const decapodesModelValid = ref(false);
const kernelManager = new KernelSessionManager();

const selectedModel = ref<Model | null>(null);
const documentId = computed(() => props.node.inputs?.[1]?.value?.[0]);

const inputCodeBlocks = ref<AssetBlock<CodeBlock>[]>([]);

Expand Down Expand Up @@ -319,6 +322,11 @@ async function handleCode() {
const modelId = await codeBlocksToAmr(newCode, file);

clonedState.value.modelId = modelId;

if (documentId.value && modelId) {
// handle this synchronously so that we can see the model while the model card is generating
profile(modelId);
}
emit('append-output-port', {
label: `Output - ${props.node.outputs.length + 1}`,
state: cloneDeep(clonedState.value),
Expand Down Expand Up @@ -346,6 +354,12 @@ async function handleCode() {
}
}

async function profile(modelId: string) {
const profileModelJobId = await profileModel(modelId, documentId.value);
await fetchExtraction(profileModelJobId);
const model = await getModel(clonedState.value.modelId);
selectedModel.value = model;
}
Comment on lines +357 to +362
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of the model service.

function openModal() {
isNewModelModalVisible.value = true;
}
Expand Down
Loading