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.
Signed-off-by: Yaliang Wu <[email protected]>
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
common/src/main/java/org/opensearch/ml/common/input/execute/agent/AgentMLInput.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,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.input.execute.agent; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.ml.common.FunctionName; | ||
import org.opensearch.ml.common.dataset.MLInputDataset; | ||
import org.opensearch.ml.common.dataset.remote.RemoteInferenceInputDataSet; | ||
import org.opensearch.ml.common.input.MLInput; | ||
import org.opensearch.ml.common.utils.StringUtils; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
//Find owner , Xun? | ||
@org.opensearch.ml.common.annotation.MLInput(functionNames = {FunctionName.AGENT}) | ||
public class AgentMLInput extends MLInput { | ||
public static final String AGENT_ID_FIELD = "agent_id"; | ||
public static final String PARAMETERS_FIELD = "parameters"; | ||
|
||
@Getter @Setter | ||
private String agentId; | ||
|
||
@Builder(builderMethodName = "AgentMLInputBuilder") | ||
public AgentMLInput(String agentId, FunctionName functionName, MLInputDataset inputDataset) { | ||
this.agentId = agentId; | ||
this.algorithm = functionName; | ||
this.inputDataset = inputDataset; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(agentId); | ||
} | ||
|
||
public AgentMLInput(StreamInput in) throws IOException { | ||
super(in); | ||
this.agentId = in.readString(); | ||
} | ||
|
||
public AgentMLInput(XContentParser parser, FunctionName functionName) throws IOException { | ||
super(); | ||
this.algorithm = functionName; | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
|
||
switch (fieldName) { | ||
case AGENT_ID_FIELD: | ||
agentId = parser.text(); | ||
break; | ||
case PARAMETERS_FIELD: | ||
Map<String, String> parameters = StringUtils.getParameterMap(parser.map()); | ||
inputDataset = new RemoteInferenceInputDataSet(parameters); | ||
break; | ||
default: | ||
parser.skipChildren(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} |