Skip to content

Commit

Permalink
adding blue print doc
Browse files Browse the repository at this point in the history
Signed-off-by: Dhrubo Saha <[email protected]>
  • Loading branch information
dhrubo-os committed Nov 19, 2024
1 parent 622f73d commit 1c0fe14
Show file tree
Hide file tree
Showing 3 changed files with 328 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public CohereMultiModalEmbeddingPreProcessFunction() {
public void validate(MLInput mlInput) {
validateTextDocsInput(mlInput);
List<String> docs = ((TextDocsInputDataSet) mlInput.getInputDataset()).getDocs();
if (docs == null || docs.isEmpty() || (docs.size() == 1 && docs.get(0) == null)) {
if (docs == null || docs.isEmpty() || docs.get(0) == null) {
throw new IllegalArgumentException("No image provided");
}
}

@Override
public RemoteInferenceInputDataSet process(MLInput mlInput) {
TextDocsInputDataSet inputData = (TextDocsInputDataSet) mlInput.getInputDataset();
Map<String, String> parametersMap = new HashMap<>();
Map<String, Object> parametersMap = new HashMap<>();

/**
* Cohere multi-modal model expects either image or texts, not both.
* For image, customer can use this pre-process function. For texts, customer can use
* connector.pre_process.cohere.embedding
* Cohere expects An array of image data URIs for the model to embed. Maximum number of images per call is 1.
*/
parametersMap.put("images", inputData.getDocs().get(0));
parametersMap.put("images", inputData.getDocs());
return RemoteInferenceInputDataSet
.builder()
.parameters(convertScriptStringToJsonString(Map.of("parameters", parametersMap)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testProcess_whenCorrectInput_expectCorrectOutput() {
MLInput mlInput = MLInput.builder().algorithm(FunctionName.TEXT_EMBEDDING).inputDataset(textDocsInputDataSet).build();
RemoteInferenceInputDataSet dataSet = function.apply(mlInput);
assertEquals(1, dataSet.getParameters().size());
assertEquals("imageString", dataSet.getParameters().get("images"));
assertEquals("[\"imageString\"]", dataSet.getParameters().get("images"));

}

Expand Down
Loading

0 comments on commit 1c0fe14

Please sign in to comment.