Skip to content

Commit

Permalink
Adding model group id to integ tests (#189)
Browse files Browse the repository at this point in the history
* Update version to 2.8-SNAPSHOT

Signed-off-by: Martin Gaievski <[email protected]>

* Fix Model group id in integ tests

Signed-off-by: Martin Gaievski <[email protected]>

---------

Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski authored Jun 1, 2023
1 parent 3547d05 commit 5228fc7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.opensearch.neuralsearch.common.VectorUtil.vectorAsListToArray;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
Expand Down Expand Up @@ -88,6 +89,9 @@ protected void updateClusterSettings(String settingKey, Object value) {
}

protected String uploadModel(String requestBody) throws Exception {
String modelGroupId = registerModelGroup();
// model group id is dynamically generated, we need to update model update request body after group is registered
requestBody = requestBody.replace("<MODEL_GROUP_ID>", modelGroupId);
Response uploadResponse = makeRequest(
client(),
"POST",
Expand Down Expand Up @@ -492,4 +496,26 @@ protected static class KNNFieldConfig {
private final Integer dimension;
private final SpaceType spaceType;
}

private String registerModelGroup() throws IOException, URISyntaxException {
String modelGroupRegisterRequestBody = Files.readString(
Path.of(classLoader.getResource("processor/CreateModelGroupRequestBody.json").toURI())
);
Response modelGroupResponse = makeRequest(
client(),
"POST",
"/_plugins/_ml/model_groups/_register",
null,
toHttpEntity(modelGroupRegisterRequestBody),
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana"))
);
Map<String, Object> modelGroupResJson = XContentHelper.convertToMap(
XContentFactory.xContent(XContentType.JSON),
EntityUtils.toString(modelGroupResponse.getEntity()),
false
);
String modelGroupId = modelGroupResJson.get("model_group_id").toString();
assertNotNull(modelGroupId);
return modelGroupId;
}
}
4 changes: 4 additions & 0 deletions src/test/resources/processor/CreateModelGroupRequestBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test_model_group_public",
"description": "This is a public model group"
}
1 change: 1 addition & 0 deletions src/test/resources/processor/UploadModelRequestBody.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"model_format": "TORCH_SCRIPT",
"model_task_type": "text_embedding",
"model_content_hash_value": "e13b74006290a9d0f58c1376f9629d4ebc05a0f9385f40db837452b167ae9021",
"model_group_id": "<MODEL_GROUP_ID>",
"model_config": {
"model_type": "bert",
"embedding_dimension": 768,
Expand Down

0 comments on commit 5228fc7

Please sign in to comment.