diff --git a/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue index c993f6600a..4361001a64 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue @@ -240,10 +240,8 @@ const initialize = async () => { if (state.interventionPolicy?.id) { // copy the state into the knobs if it exists selectedPolicy.value = await getInterventionPolicyById(state.interventionPolicy.id); - knobs.value.transientInterventionPolicy = cloneDeep(state.interventionPolicy); - } else { - knobs.value.transientInterventionPolicy = cloneDeep(state.interventionPolicy); } + knobs.value.transientInterventionPolicy = cloneDeep(state.interventionPolicy); }; const applyInterventionPolicy = (interventionPolicy: InterventionPolicy) => { diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts b/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts index 3cd33d48fb..c8d2494e3b 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts @@ -1,19 +1,15 @@ import { WorkflowOperationTypes } from '@/types/workflow'; import type { Operation, BaseState } from '@/types/workflow'; import type { ModelConfiguration } from '@/types/Types'; +import { NotebookHistory } from '@/services/notebook'; import configureModel from '@assets/svg/operator-images/configure-model.svg'; export const name = 'ModelConfigOperation'; -export interface ModelEditCode { - code: string; - timestamp: number; -} - export interface ModelConfigOperationState extends BaseState { transientModelConfig: ModelConfiguration; - modelEditCodeHistory: ModelEditCode[]; - hasCodeBeenRun: boolean; + notebookHistory: NotebookHistory[]; + hasCodeRun: boolean; } export const blankModelConfig: ModelConfiguration = { @@ -43,9 +39,9 @@ export const ModelConfigOperation: Operation = { action: async () => ({}), initState: () => { const init: ModelConfigOperationState = { - modelEditCodeHistory: [], - hasCodeBeenRun: false, - transientModelConfig: blankModelConfig + transientModelConfig: blankModelConfig, + notebookHistory: [], + hasCodeRun: false }; return init; } diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue index 837ce624f0..c8c9ec8892 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue @@ -73,7 +73,7 @@ @@ -135,8 +135,7 @@ - -
+
@@ -250,6 +245,7 @@ import TeraSliderPanel from '@/components/widgets/tera-slider-panel.vue'; import { useConfirm } from 'primevue/useconfirm'; import Dropdown from 'primevue/dropdown'; import TeraToggleableEdit from '@/components/widgets/tera-toggleable-edit.vue'; +import { saveCodeToState } from '@/services/notebook'; import TeraModelConfigurationItem from './tera-model-configuration-item.vue'; import { ModelConfigOperation, ModelConfigOperationState, blankModelConfig } from './model-config-operation'; @@ -316,6 +312,7 @@ const buildJupyterContext = () => { }; }; const codeText = ref('# This environment contains the variable "model_config" to be read and updated'); +const llmQuery = ref(''); const llmThoughts = ref([]); const notebookResponse = ref(); const executeResponse = ref({ @@ -379,7 +376,8 @@ const runFromCode = () => { knobs.value.transientModelConfig = data.content; if (executedCode) { - saveCodeToState(executedCode, true); + updateCodeState(executedCode, true); + createConfiguration(); } }) .register('any_execute_reply', (data) => { @@ -395,21 +393,15 @@ const runFromCode = () => { }); }; -// FIXME: Copy pasted in 3 locations, could be written cleaner and in a service -const saveCodeToState = (code: string, hasCodeBeenRun: boolean) => { - const state = cloneDeep(props.node.state); - state.hasCodeBeenRun = hasCodeBeenRun; +function updateLlmQuery(query: string) { + llmThoughts.value = []; + llmQuery.value = query; +} - // for now only save the last code executed, may want to save all code executed in the future - const codeHistoryLength = props.node.state.modelEditCodeHistory.length; - const timestamp = Date.now(); - if (codeHistoryLength > 0) { - state.modelEditCodeHistory[0] = { code, timestamp }; - } else { - state.modelEditCodeHistory.push({ code, timestamp }); - } +function updateCodeState(code: string = codeText.value, hasCodeRun: boolean = true) { + const state = saveCodeToState(props.node, code, hasCodeRun, llmQuery.value, llmThoughts.value); emit('update-state', state); -}; +} const initializeEditor = (editorInstance: any) => { editor = editorInstance; @@ -497,27 +489,22 @@ const downloadConfiguredModel = async (configuration: ModelConfiguration = knobs const createConfiguration = async () => { if (!model.value || isSaveDisabled.value) return; - - const state = cloneDeep(props.node.state); - const modelConfig = cloneDeep(knobs.value.transientModelConfig); const data = await createModelConfiguration(modelConfig); - if (!data) { logger.error('Failed to create model configuration'); return; } knobs.value.transientModelConfig = cloneDeep(data); - state.transientModelConfig = knobs.value.transientModelConfig; useToastService().success('', 'Created model configuration'); emit('append-output', { type: ModelConfigOperation.outputs[0].type, - label: state.transientModelConfig.name, + label: data.name, value: data.id, isSelected: false, - state + state: cloneDeep(props.node.state) }); }; @@ -575,7 +562,6 @@ const onSelectConfiguration = (config: ModelConfiguration) => { }; const applyConfigValues = (config: ModelConfiguration) => { - const state = cloneDeep(props.node.state); knobs.value.transientModelConfig = cloneDeep(config); // Update output port: @@ -593,13 +579,12 @@ const applyConfigValues = (config: ModelConfiguration) => { // If the output does not already exist else { // Append this config to the output. - state.transientModelConfig = knobs.value.transientModelConfig; emit('append-output', { type: ModelConfigOperation.outputs[0].type, label: config.name, value: config.id, isSelected: false, - state + state: cloneDeep(props.node.state) }); } logger.success(`Configuration applied ${config.name}`); @@ -621,9 +606,7 @@ const resetConfiguration = () => { message: 'This will reset all values original values of the configuration.', accept: () => { const originalConfig = suggestedConfigurationContext.value.tableData.find((c) => c.id === selectedConfigId.value); - if (originalConfig) { - applyConfigValues(originalConfig); - } + if (originalConfig) applyConfigValues(originalConfig); }, acceptLabel: 'Confirm', rejectLabel: 'Cancel' @@ -687,7 +670,7 @@ onUnmounted(() => { padding-bottom: var(--gap-2); } -#notebook-section:deep(main) { +.notebook-section:deep(main) { gap: var(--gap-small); position: relative; } diff --git a/packages/client/hmi-client/src/services/notebook.ts b/packages/client/hmi-client/src/services/notebook.ts index 5f8294d7fd..a250a2100a 100644 --- a/packages/client/hmi-client/src/services/notebook.ts +++ b/packages/client/hmi-client/src/services/notebook.ts @@ -9,7 +9,7 @@ export interface NotebookHistory { } // A common pattern used to save code from a notebook within an operator -// This is ready to be ported to nodes such as tera-model-config and tera-stratify-mira +// One more operator to port this to: tera-stratify-mira // Not ported yet since this will ruin the states of the nodes that already exist due to their differently named properties export const saveCodeToState = ( node: WorkflowNode, diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java index 04f6945e55..327713c982 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java @@ -350,7 +350,7 @@ public ResponseEntity createModelConfiguration( } return ResponseEntity.status(HttpStatus.CREATED).body( - modelConfigurationService.createAsset(modelConfiguration, projectId, permission) + modelConfigurationService.createAsset(modelConfiguration.clone(), projectId, permission) ); } catch (final IOException e) { log.error("Unable to get model configuration from postgres db", e);