Skip to content

Commit

Permalink
remove skema-rs (#6566)
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis authored Feb 11, 2025
1 parent 2e96de2 commit 5581ad5
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 148 deletions.
21 changes: 5 additions & 16 deletions packages/client/hmi-client/src/services/document-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ async function getDocumentAsset(documentId: string, projectId?: string): Promise
/**
* This is a helper function which uploads an arbitrary document to TDS and creates a new document asset from it.
* @param file the file to upload
* @param userName owner of this project
* @param projectId the project ID
* @param description? description of the file. Optional. If not given description will be just the file name
* @param progress? reference to display in ui
* @param userId
* @param description
* @param progress
*/
async function uploadDocumentAssetToProject(
file: File,
Expand Down Expand Up @@ -90,7 +89,7 @@ async function createNewDocumentFromGithubFile(

/**
* Creates a new document asset in TDS and returns the new document asset object id
* @param document the document asset to create
* @param documentAsset
*/
async function createNewDocumentAsset(documentAsset: DocumentAsset): Promise<DocumentAsset | null> {
const response = await API.post('/document-asset', documentAsset);
Expand All @@ -102,6 +101,7 @@ async function createNewDocumentAsset(documentAsset: DocumentAsset): Promise<Doc
* Adds a file to a document in TDS
* @param documentId the documentId to add the file to
* @param file the file to upload
* @param progress
*/
async function addFileToDocumentAsset(documentId: string, file: File, progress?: Ref<number>): Promise<boolean> {
const formData = new FormData();
Expand Down Expand Up @@ -149,16 +149,6 @@ async function getDocumentFileAsText(documentId: string, fileName: string): Prom
return response.data;
}

async function getEquationFromImageUrl(documentId: string, filename: string): Promise<string | null> {
const response = await API.get(`/document-asset/${documentId}/image-to-equation?filename=${filename}`, {});

if (!response) {
return null;
}

return response.data;
}

async function getBulkDocumentAssets(docIDs: string[]) {
const result: DocumentAsset[] = [];
const promiseList = [] as Promise<DocumentAsset | null>[];
Expand All @@ -181,6 +171,5 @@ export {
getBulkDocumentAssets,
getDocumentAsset,
getDocumentFileAsText,
getEquationFromImageUrl,
uploadDocumentAssetToProject
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package software.uncharted.terarium.hmiserver.controller.dataservice;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -10,7 +9,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -49,16 +47,11 @@
import software.uncharted.terarium.hmiserver.models.dataservice.ResponseStatus;
import software.uncharted.terarium.hmiserver.models.dataservice.document.DocumentAsset;
import software.uncharted.terarium.hmiserver.proxies.jsdelivr.JsDelivrProxy;
import software.uncharted.terarium.hmiserver.proxies.skema.SkemaRustProxy;
import software.uncharted.terarium.hmiserver.proxies.skema.SkemaUnifiedProxy;
import software.uncharted.terarium.hmiserver.security.Roles;
import software.uncharted.terarium.hmiserver.service.CurrentUserService;
import software.uncharted.terarium.hmiserver.service.ExtractionService;
import software.uncharted.terarium.hmiserver.service.data.DocumentAssetService;
import software.uncharted.terarium.hmiserver.service.data.ProjectService;
import software.uncharted.terarium.hmiserver.service.gollm.EmbeddingService;
import software.uncharted.terarium.hmiserver.utils.Messages;
import software.uncharted.terarium.hmiserver.utils.rebac.ReBACService;
import software.uncharted.terarium.hmiserver.utils.rebac.Schema;

@RequestMapping("/document-asset")
Expand All @@ -68,26 +61,12 @@
public class DocumentController {

final Config config;
final ReBACService reBACService;
final CurrentUserService currentUserService;
final Messages messages;

final SkemaUnifiedProxy skemaUnifiedProxy;

final SkemaRustProxy skemaRustProxy;

final JsDelivrProxy gitHubProxy;

final DownloadService downloadService;

private final ProjectService projectService;

final DocumentAssetService documentAssetService;

final ObjectMapper objectMapper;
final ExtractionService extractionService;
final EmbeddingService embeddingService;

@PostMapping
@Secured(Roles.USER)
@Operation(summary = "Create a new document")
Expand Down Expand Up @@ -157,10 +136,7 @@ public ResponseEntity<DocumentAsset> updateDocument(

try {
final Optional<DocumentAsset> updated = documentAssetService.updateAsset(document, projectId, permission);
if (updated.isEmpty()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(updated.get());
return updated.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
} catch (final IOException e) {
final String error = "Unable to update document";
log.error(error, e);
Expand Down Expand Up @@ -585,65 +561,4 @@ public ResponseEntity<String> getDocumentFileAsText(
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, error);
}
}

/**
* Post Images to Equations Unified service to get an AMR
*
* @param documentId document id
* @param filename filename of the image
* @return LaTeX representation of the equation
*/
@GetMapping("/{id}/image-to-equation")
@Secured(Roles.USER)
@Operation(summary = "Post Images to Equations Unified service to get an AMR")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "Converts image to string",
content = @Content(
mediaType = "application/text",
schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = String.class)
)
),
@ApiResponse(responseCode = "500", description = "There was an issue creating equation", content = @Content)
}
)
public ResponseEntity<String> postImageToEquation(
@PathVariable("id") final UUID documentId,
@RequestParam("filename") final String filename
) {
Optional<byte[]> bytes = Optional.empty();
try {
bytes = documentAssetService.fetchFileAsBytes(documentId, filename);
} catch (IOException e) {
log.error("Unable to fetch files from the document asset service", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("generic.io-error.read"));
}

if (bytes.isEmpty()) {
return ResponseEntity.notFound().build();
}

final byte[] imagesByte = bytes.get();

// Encode the image in Base 64
final String imageB64 = Base64.getEncoder().encodeToString(imagesByte);

// image -> mathML
final String mathML = skemaUnifiedProxy.postImageToEquations(imageB64).getBody();

// mathML -> LaTeX
final String latex = skemaRustProxy.convertMathML2Latex(mathML).getBody();
if (latex == null) {
log.error("Unable to convert MathML to LaTeX");
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, messages.get("skema.error.image-2-equation"));
}

// Add spaces before and after "*"
String latexWithSpaces = latex.replaceAll("(?<!\\s)\\*", " *");
latexWithSpaces = latexWithSpaces.replaceAll("\\*(?!\\s)", "* ");

return ResponseEntity.ok(latexWithSpaces);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ terarium.file-storage-s3-bucket-name=askem-staging-data-service
########################################################################################################################
# Microservice configuration
########################################################################################################################
skema-rs.url=https://skema-rs.staging.terarium.ai
skema-unified.url=https://skema-unified.staging.terarium.ai
ciemss-service.url=https://pyciemss.staging.terarium.ai

Expand Down
1 change: 0 additions & 1 deletion packages/server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ terarium.static-index-path=askem-static-index
github.url=https://api.github.com
jsdelivr.url=https://cdn.jsdelivr.net
mira-api.url=http://mira-epi-dkg-lb-dc1e19b273dedaa2.elb.us-east-1.amazonaws.com
skema-rs.url=https://skema-rs.staging.terarium.ai
skema-unified.url=https://skema-unified.staging.terarium.ai
ciemss-service.url=https://pyciemss.staging.terarium.ai

Expand Down
1 change: 0 additions & 1 deletion packages/server/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ skema.bad-code = Our model service (SKEMA) couldn't find a valid model represent
skema.bad-equations = Our model service (SKEMA) couldn't find a valid model representation. This could be due to invalid equations or an inability to parse them into the requested framework. Please review your equations and try again.
skema.bad-equations.petrinet = Our model service (SKEMA) couldn't create a valid Petrinet representation for the supplied equations. This could be due to invalid equations or an inability to parse them into the requested framework. Please review your equations and try again.
skema.error.align-model = We couldn't align the model with the selected document. Please verify that the model is valid and that the document has valid extractions.
skema.error.image-2-equation = We couldn't convert the equation image into valid LaTeX. Please verify that the image is of a valid equation.
skema.internal-error = We couldn't produce a valid model representation based on the selected resource. Please verify that the resource is valid and try again.
skema.service-unavailable = Our model service (SKEMA) is temporarily unavailable. Please try again later.

Expand Down

0 comments on commit 5581ad5

Please sign in to comment.