Skip to content

Commit

Permalink
Add documentId on eqautionsToAMR service request (#4719)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Birk <[email protected]>
Co-authored-by: Shawn Yama <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 9, 2024
1 parent 65d6a41 commit 8b9defd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ref, watch } from 'vue';
import TeraMathEditor from '@/components/mathml/tera-math-editor.vue';
import TeraEquationContainer from '@/components/model/petrinet/tera-equation-container.vue';
import type { Model } from '@/types/Types';
import { equationsToAMR } from '@/services/knowledge';
import { equationsToAMR, EquationsToAMRRequest } from '@/services/knowledge';
import { cleanLatexEquations } from '@/utils/math';
import { isEmpty } from 'lodash';
import { useToastService } from '@/services/toast';
Expand Down Expand Up @@ -76,7 +76,8 @@ const updateLatexFormula = (equationsList: string[]) => {
const updateModelFromEquations = async () => {
isUpdating.value = true;
isEditing.value = false;
const modelId = await equationsToAMR(equations.value, 'petrinet', props.model.id);
const request: EquationsToAMRRequest = { equations: equations.value, modelId: props.model.id };
const modelId = await equationsToAMR(request);
if (modelId) {
emit('model-updated');
useToastService().success('Success', `Model Updated from equation`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import { getDocumentAsset, getEquationFromImageUrl } from '@/services/document-a
import type { Card, DocumentAsset, DocumentExtraction, Model } from '@/types/Types';
import { cloneDeep, unionBy } from 'lodash';
import Image from 'primevue/image';
import { equationsToAMR } from '@/services/knowledge';
import { equationsToAMR, type EquationsToAMRRequest } from '@/services/knowledge';
import Button from 'primevue/button';
import Dropdown from 'primevue/dropdown';
import { getModel, updateModel } from '@/services/model';
Expand Down Expand Up @@ -246,7 +246,12 @@ async function onRun() {
.filter((e) => e.includeInProcess && !e.asset.extractionError)
.map((e) => e.asset.text);
const modelId = await equationsToAMR(equations, clonedState.value.modelFramework);
const request: EquationsToAMRRequest = {
equations,
framework: clonedState.value.modelFramework,
documentId: document.value?.id
};
const modelId = await equationsToAMR(request);
if (!modelId) return;
if (document.value?.id) await generateCard(document.value.id);
Expand Down
25 changes: 17 additions & 8 deletions packages/client/hmi-client/src/services/knowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@ import { ClientEventType } from '@/types/Types';
import { logger } from '@/utils/logger';
import { AxiosResponse } from 'axios';

/**
* Transform a list of LaTeX or mathml strings to an AMR
/** 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
* @param documentId string= - the document id source of the equations
*/
export interface EquationsToAMRRequest {
equations: string[];
framework?: string;
modelId?: Model['id'];
documentId?: DocumentAsset['id'];
}

/**
* Transform a list of LaTeX or mathml strings to an AMR
* @param request EquationsToAMRRequest
* @return {Promise<any>}
*/
export const equationsToAMR = async (
equations: string[],
framework: string = 'petrinet',
modelId?: string
): Promise<string | null> => {
export const equationsToAMR = async (request: EquationsToAMRRequest): Promise<string | null> => {
const { equations, framework: model = 'petrinet', modelId, documentId } = request;
try {
const response: AxiosResponse<string> = await API.post(`/knowledge/equations-to-model`, {
model: framework,
model,
modelId,
documentId,
equations
});
return response.data;
Expand Down

0 comments on commit 8b9defd

Please sign in to comment.