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

Correct regrid context. #3143

Merged
merged 4 commits into from
Mar 25, 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
Expand Up @@ -49,6 +49,10 @@
<span class="p-button-text">Reset</span>
</Button>
</div>
<div v-for="(ele, indx) in contextInfo" :key="indx" class="contextInfo">
<span>context variable: {{ indx }}</span>
<span>filename: {{ ele.filename }}</span>
</div>
<tera-jupyter-chat
ref="chat"
:show-jupyter-settings="true"
Expand Down Expand Up @@ -131,7 +135,7 @@ const runningSessions = ref<any[]>([]);
const confirm = useConfirm();

const props = defineProps<{
assets: { id: string; type: string }[];
assets: { id: string; filename: string }[];
showKernels: boolean;
showChatThoughts: boolean;
notebookSession?: NotebookSession;
Expand All @@ -143,7 +147,7 @@ const kernelStatus = ref(<string>'');
const kernelState = ref(null);
const autoExpandPreview = ref(<boolean>true);
const actionTarget = ref('df');

const contextInfo: any = ref({});
const showSaveInput = ref(<boolean>false);
const saveAsName = ref(<string | null>'');
const toast = useToastService();
Expand Down Expand Up @@ -178,30 +182,20 @@ const setKernelContext = (kernel: IKernelConnection, context_info) => {
kernel?.sendJupyterMessage(message);
};

// FIXME: this is a bit fragile, the output is meant to match the terms used in askem-beaker
// and not necessarily asset type enums
const toAssetType = (t: string) => {
if (t.endsWith('Id')) {
return t.substring(0, t.length - 2);
}
throw new Error(`Cannot convert type ${t}`);
};

jupyterSession.kernelChanged.connect((_context, kernelInfo) => {
const kernel = kernelInfo.newValue;

const contextInfo: any = {};
props.assets.forEach((asset, i) => {
const key = `d${i + 1}`;
contextInfo[key] = {
id: asset.id,
asset_type: toAssetType(asset.type)
contextInfo.value[key] = {
hmi_dataset_id: asset.id,
filename: asset.filename
};
});
if (kernel?.name === 'beaker_kernel') {
setKernelContext(kernel as IKernelConnection, {
context: 'climate_data_utility',
context_info: contextInfo
context_info: contextInfo.value
});
}
});
Expand Down Expand Up @@ -416,6 +410,10 @@ const onDownloadResponse = (payload) => {
</script>

<style scoped>
.contextInfo {
display: flex;
flex-direction: column;
}
.container {
margin-left: 1rem;
margin-right: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
<script setup lang="ts">
// Proxy to use tera-dataset via a workflow context

import { WorkflowNode, WorkflowPortStatus } from '@/types/workflow';
import { WorkflowNode } from '@/types/workflow';
import TeraDatasetJupyterRegriddingPanel from '@/components/dataset/tera-dataset-jupyter-regridding-panel.vue';
import { computed, onMounted, ref } from 'vue';
import { onMounted, ref } from 'vue';
import { createNotebookSession, getNotebookSessionById } from '@/services/notebook-session';
import type { NotebookSession } from '@/types/Types';
import { getDataset } from '@/services/dataset';
import type { NotebookSession, Dataset } from '@/types/Types';
import { cloneDeep } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import TeraDrilldown from '@/components/drilldown/tera-drilldown.vue';
Expand All @@ -41,14 +42,7 @@ const emit = defineEmits(['append-output', 'update-state', 'close']);

const showKernels = ref(<boolean>false);
const showChatThoughts = ref(<boolean>false);
const assets = computed(() =>
props.node.inputs
.filter((inputNode) => inputNode.status === WorkflowPortStatus.CONNECTED && inputNode.value)
.map((inputNode) => ({
type: inputNode.type,
id: inputNode.value![0]
}))
);
const assets = ref([]);

const notebookSession = ref(<NotebookSession | undefined>undefined);

Expand All @@ -72,6 +66,26 @@ onMounted(async () => {
}
}

// Get filenames and set up assets object to be sent as context:
const allDatasets: Dataset[] = [];
await Promise.all(
props.node.inputs.map(async (ele) => {
if (ele?.value?.[0]) {
const dataset = await getDataset(ele?.value?.[0]);
if (dataset) allDatasets.push(dataset);
}
})
);

allDatasets.forEach((dataset) => {
if (dataset.id && dataset.fileNames?.[0]) {
assets.value.push({
id: dataset.id,
filename: dataset.fileNames[0]
});
}
});

notebookSession.value = await getNotebookSessionById(notebookSessionId!);
});

Expand Down
Loading