Skip to content

Commit

Permalink
Model extractions update (#5127)
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis authored Oct 10, 2024
1 parent 59ae904 commit 2ccdd44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 61 deletions.
57 changes: 4 additions & 53 deletions packages/client/hmi-client/src/services/knowledge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import API from '@/api/api';
import { AxiosResponse } from 'axios';
import { extractionStatusUpdateHandler, subscribe } from '@/services/ClientEventService';
import type { Code, Dataset, DocumentAsset, Model } from '@/types/Types';
import { ClientEventType } from '@/types/Types';
import { type Dataset, type DocumentAsset, type Model, ClientEventType } from '@/types/Types';
import { logger } from '@/utils/logger';
import { AxiosResponse } from 'axios';

/** Define the request type
/**
* Define the request type
* @param equations string[] - list of LaTeX or mathml strings representing a model
* @param framework string= - the framework to use for the extraction, default to 'petrinet'
* @param modelId string= - the model id to use for the extraction
Expand Down Expand Up @@ -55,70 +55,21 @@ export const profileDataset = async (datasetId: Dataset['id'], documentId: Docum

/** Extract text and artifacts from a PDF document */
export const extractPDF = async (documentId: DocumentAsset['id']) => {
console.group('PDF COSMOS Extraction');
if (documentId) {
const response = await API.post(`/knowledge/pdf-extractions?document-id=${documentId}`);
if (response?.status === 202) {
await subscribe(ClientEventType.Extraction, extractionStatusUpdateHandler);
} else {
console.debug('Failed — ', response);
}
} else {
console.debug('Failed — No documentId provided for pdf extraction.');
}
console.groupEnd();
};

/** Extract variables from a text document */
export const extractVariables = async (documentId: DocumentAsset['id'], modelIds: Array<Model['id']>) => {
console.group('SKEMA Variable extraction');
if (documentId) {
const url = `/knowledge/variable-extractions?document-id=${documentId}&model-ids=${modelIds}`;
const response = await API.post(url);
if (response?.status === 202) {
await subscribe(ClientEventType.Extraction, extractionStatusUpdateHandler);
} else {
console.debug('Failed — ', response);
}
} else {
console.debug('Failed — No documentId provided for variable extraction.');
}
console.groupEnd();
};

export async function codeToAMR(
codeId: string,
name: string = '',
description: string = '',
dynamicsOnly: boolean = false,
llmAssisted: boolean = false
): Promise<Model | null> {
const response = await API.post(
`/knowledge/code-to-amr?code-id=${codeId}&name=${name}&description=${description}&dynamics-only=${dynamicsOnly}&llm-assisted=${llmAssisted}`
);
if (response?.status === 200) {
return response.data;
}
logger.error(`Code to AMR request failed`, { toastTitle: 'Error' });
return null;
}

export async function codeBlocksToAmr(code: Code, file: File): Promise<Model | null> {
const formData = new FormData();
const blob = new Blob([JSON.stringify(code)], {
type: 'application/json'
});
formData.append('code', blob);
formData.append('file', file);
const response = await API.post(`/knowledge/code-blocks-to-model`, formData, {
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data'
}
});
if (response?.status === 200) {
return response.data;
}
logger.error(`Code to AMR request failed`, { toastTitle: 'Error' });
return null;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Model extraction
## Model from equations
Please go through __every__ step of the test scenario.\
Report any issues into GitHub: [open an issue](https://github.com/DARPA-ASKEM/terarium/issues/new?assignees=&labels=bug%2C+Q%26A&template=qa-issue.md&title=%5BBUG%5D%3A+).

Expand All @@ -13,18 +13,20 @@ Report any issues into GitHub: [open an issue](https://github.com/DARPA-ASKEM/te
### 2. Upload a PDF
1. Upload _the Document_ [SIR.pdf](../data/SIR.pdf)
2. Wait for final notification of document extraction
3. Open _the Document_ and check that extractions are visible

### 3. Extract model from document
1. Create a new workflow named `Extract model from document`
1. Create a new workflow named `Model from equations`
2. Drag and drop _the Document_ onto the workflow
3. Add the operator `Create model from equations`
4. Link _the Document_ and open the operator
5. Select the equations `S`, `I` and `R` and create model
6. Save model and name as `SIR`
6. Save the model for re-use and name it `SIR`
7. Make sure that the name has been updated:
a. Operator drilldown output dropdown
b. Operator node output label
8. The model is available in the resource panel

### 4. Check extractions from document
1. Open model `SIR`
2. Is the TA1 _model card_, extracted with `mit-tr` available?
3. Is the TA4 _model card_, extracted from `gollm-taskrunner` available?
4. Are the _variables extractions_ available in the `Other` accordion?
1. Wait for the notification that the model enrichment has been completed
2. Is the model description been filled with relevant information from the document?
3. Are the variables description been filled with relevant information from the document?

0 comments on commit 2ccdd44

Please sign in to comment.