Skip to content

Commit

Permalink
Fix messaging around GoLLM tasks #5076 (#5077)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvince2 authored Oct 7, 2024
1 parent ae443d7 commit 0550c78
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions packages/client/hmi-client/src/services/goLLM.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import API, { FatalError, TaskEventHandlers, TaskHandler } from '@/api/api';
import API from '@/api/api';
import type { TaskResponse } from '@/types/Types';
import { TaskStatus } from '@/types/Types';
import { logger } from '@/utils/logger';

/**
Expand All @@ -10,25 +9,12 @@ import { logger } from '@/utils/logger';
*/
export async function modelCard(modelId: string, documentId?: string): Promise<void> {
try {
const response = await API.post<TaskResponse>('/gollm/model-card', null, {
await API.post<TaskResponse>('/gollm/model-card', null, {
params: {
'model-id': modelId,
'document-id': documentId
}
});
// FIXME: I think we need to refactor the response interceptors so that we can handle errors here, or even in the interceptor itself...might be worth a discussion
const taskId = response.data.id;
await handleTaskById(taskId, {
ondata(data, closeConnection) {
if (data?.status === TaskStatus.Failed) {
closeConnection();
throw new FatalError('Task failed');
}
if (data.status === TaskStatus.Success) {
closeConnection();
}
}
});
} catch (err) {
logger.error(err);
}
Expand All @@ -53,26 +39,13 @@ export async function interventionPolicyFromDocument(

export async function enrichModelMetadata(modelId: string, documentId: string, overwrite: boolean): Promise<void> {
try {
const response = await API.get<TaskResponse>('/gollm/enrich-model-metadata', {
await API.get<TaskResponse>('/gollm/enrich-model-metadata', {
params: {
'model-id': modelId,
'document-id': documentId,
overwrite
}
});

const taskId = response.data.id;
await handleTaskById(taskId, {
ondata(data, closeConnection) {
if (data?.status === TaskStatus.Failed) {
closeConnection();
throw new FatalError('Task failed');
}
if (data.status === TaskStatus.Success) {
closeConnection();
}
}
});
} catch (err) {
logger.error(err);
}
Expand Down Expand Up @@ -149,13 +122,3 @@ export async function cancelTask(taskId: string): Promise<void> {
logger.error(`An issue occurred while cancelling task with id: ${taskId}. ${err}`);
}
}

/**
* Handles task for a given task ID.
* @param {string} id - The task ID.
*/
export async function handleTaskById(id: string, handlers: TaskEventHandlers): Promise<TaskHandler> {
const taskHandler = new TaskHandler(`/gollm/${id}`, handlers);
await taskHandler.start();
return taskHandler;
}

0 comments on commit 0550c78

Please sign in to comment.