forked from opensearch-project/ml-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add postprocess function for batch inferernce jobArn
Signed-off-by: Yaliang Wu <[email protected]>
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...arch/ml/common/connector/functions/postprocess/BedrockBatchJobArnPostProcessFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.connector.functions.postprocess; | ||
|
||
import org.opensearch.ml.common.output.model.ModelTensor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class BedrockBatchJobArnPostProcessFunction extends ConnectorPostProcessFunction<Map<String, String>> { | ||
public static final String JOB_ARN = "jobArn"; | ||
public static final String PROCESSED_JOB_ARN = "processedJobArn"; | ||
|
||
@Override | ||
public void validate(Object input) { | ||
if (!(input instanceof Map)) { | ||
throw new IllegalArgumentException("Post process function input is not a Map."); | ||
} | ||
Map<String, String> jobInfo = (Map<String, String>) input; | ||
if (!(jobInfo.containsKey(JOB_ARN))) { | ||
throw new IllegalArgumentException("Bedrock batch job arn missing."); | ||
} | ||
} | ||
|
||
@Override | ||
public List<ModelTensor> process(Map<String, String> jobInfo) { | ||
List<ModelTensor> modelTensors = new ArrayList<>(); | ||
Map<String, String> processedResult = new HashMap<>(); | ||
processedResult.putAll(jobInfo); | ||
String jobArn = jobInfo.get(JOB_ARN); | ||
processedResult.put(PROCESSED_JOB_ARN, jobArn.replace("/", "%2F")); | ||
modelTensors | ||
.add( | ||
ModelTensor | ||
.builder() | ||
.name("response") | ||
.dataAsMap(processedResult) | ||
.build() | ||
); | ||
return modelTensors; | ||
} | ||
} |