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

model comparison gollm cache issue #4709

Merged
merged 13 commits into from
Sep 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ const sampleAgentQuestions = [
'Compare the two models and visualize and display them.'
];
let compareModelsTaskId = '';
let compareModelsTaskOutput = '';

const modelsToCompare = ref<Model[]>([]);
const modelCardsToCompare = ref<any[]>([]);
Expand Down Expand Up @@ -290,30 +289,32 @@ async function buildJupyterContext() {
}
}

// Generate once the comparison task has been completed
function generateOverview(output: string) {
overview.value = markdownit().render(JSON.parse(b64DecodeUnicode(output)).response);
emit('update-status', OperatorStatus.DEFAULT); // This is a custom way of granting a default status to the operator, since it has no output
}

// Create a task to compare the models
async function processCompareModels(modelIds: string[]) {
const taskRes = await compareModels(modelIds, props.node.workflowId, props.node.id);
compareModelsTaskId = taskRes.id;
if (taskRes.status === TaskStatus.Success) {
compareModelsTaskOutput = taskRes.output;
generateOverview(taskRes.output);
}
}

function assignOverview(b64overview: string) {
overview.value = markdownit().render(JSON.parse(b64DecodeUnicode(b64overview)).response);
}

async function generateOverview() {
// Generate once the comparison task has been completed
if (!compareModelsTaskOutput) return;
assignOverview(compareModelsTaskOutput);
emit('update-status', OperatorStatus.DEFAULT); // This is a custom way of granting a default status to the operator, since it has no output
}

// Listen for the task completion event
useClientEvent(ClientEventType.TaskGollmCompareModel, (event: ClientEvent<TaskResponse>) => {
if (!event.data || event.data.id !== compareModelsTaskId) return;
if (event.data.status !== TaskStatus.Success) return;
compareModelsTaskOutput = event.data.output;
generateOverview();
if (
!event.data ||
event.data.id !== compareModelsTaskId ||
!isEmpty(overview.value) ||
event.data.status !== TaskStatus.Success
) {
return;
}
generateOverview(event.data.output);
});

onMounted(async () => {
Expand All @@ -333,8 +334,8 @@ onMounted(async () => {
modelCardsToCompare.value = modelsToCompare.value.map(({ metadata }) => metadata?.gollmCard);
fields.value = [...new Set(modelCardsToCompare.value.flatMap((card) => (card ? Object.keys(card) : [])))];

buildJupyterContext();
processCompareModels(modelIds);
await buildJupyterContext();
await processCompareModels(modelIds);
});

onUnmounted(() => {
Expand Down