Skip to content

Commit

Permalink
refactor: keep file read consistent
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Apr 13, 2024
1 parent 641d3cb commit 45a8b33
Showing 1 changed file with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,48 +64,44 @@ protected final Optional<String> getBWCVersion() {
}

protected String uploadTextEmbeddingModel() throws Exception {
String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI()));
String requestBody = getRequestBodyFromFile("processor/UploadModelRequestBody.json");
return registerModelGroupAndGetModelId(requestBody);
}

protected String registerModelGroupAndGetModelId(final String requestBody) throws Exception {
String modelGroupRegisterRequestBody = Files.readString(
Path.of(classLoader.getResource("processor/CreateModelGroupRequestBody.json").toURI())
);
String modelGroupRegisterRequestBody = getRequestBodyFromFile("processor/CreateModelGroupRequestBody.json");
String modelGroupId = registerModelGroup(String.format(LOCALE, modelGroupRegisterRequestBody, generateModelId()));
return uploadModel(String.format(LOCALE, requestBody, modelGroupId));
}

protected void createPipelineProcessor(final String modelId, final String pipelineName) throws Exception {
String requestBody = Files.readString(Path.of(classLoader.getResource("processor/PipelineConfiguration.json").toURI()));
String requestBody = getRequestBodyFromFile("processor/PipelineConfiguration.json");
createPipelineProcessor(requestBody, pipelineName, modelId);
}

protected String uploadSparseEncodingModel() throws Exception {
String requestBody = Files.readString(
Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI())
);
String requestBody = getRequestBodyFromFile("processor/UploadSparseEncodingModelRequestBody.json");
return registerModelGroupAndGetModelId(requestBody);
}

protected void createPipelineForTextImageProcessor(final String modelId, final String pipelineName) throws Exception {
String requestBody = Files.readString(
Path.of(classLoader.getResource("processor/PipelineForTextImageProcessorConfiguration.json").toURI())
);
String requestBody = getRequestBodyFromFile("processor/PipelineForTextImageProcessorConfiguration.json");
createPipelineProcessor(requestBody, pipelineName, modelId);
}

protected void createPipelineForSparseEncodingProcessor(final String modelId, final String pipelineName) throws Exception {
String requestBody = Files.readString(
Path.of(classLoader.getResource("processor/PipelineForSparseEncodingProcessorConfiguration.json").toURI())
);
String requestBody = getRequestBodyFromFile("processor/PipelineForSparseEncodingProcessorConfiguration.json");
createPipelineProcessor(requestBody, pipelineName, modelId);
}

protected void createPipelineForTextChunkingProcessor(String pipelineName) throws Exception {
URL pipelineURLPath = classLoader.getResource("processor/PipelineForTextChunkingProcessorConfiguration.json");
Objects.requireNonNull(pipelineURLPath);
String requestBody = Files.readString(Path.of(pipelineURLPath.toURI()));
String requestBody = getRequestBodyFromFile("processor/PipelineForTextChunkingProcessorConfiguration.json");
createPipelineProcessor(requestBody, pipelineName, "");
}

private String getRequestBodyFromFile(String filePath) throws Exception {
URL fileURLPath = classLoader.getResource(filePath);
Objects.requireNonNull(fileURLPath);
return Files.readString(Path.of(fileURLPath.toURI()));
}
}

0 comments on commit 45a8b33

Please sign in to comment.