Skip to content

Commit ef75795

Browse files
committed
add example of responsestr and change default size to 100
Signed-off-by: zane-neo <zaniu@amazon.com>
1 parent 0714b07 commit ef75795

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/CatIndexTool.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class CatIndexTool implements Tool {
6666
public static final String TYPE = "CatIndexTool";
6767
// This needs to be changed once it's changed in opensearch core in RestIndicesListAction.
6868
private static final int MAX_SUPPORTED_LIST_INDICES_PAGE_SIZE = 5000;
69-
private static final int DEFAULT_PAGE_SIZE = 1;
69+
public static final int DEFAULT_PAGE_SIZE = 100;
7070
private static final String DEFAULT_DESCRIPTION = String
7171
.join(
7272
" ",

plugin/src/test/java/org/opensearch/ml/tools/CatIndexToolIT.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.junit.Before;
1717
import org.opensearch.client.Response;
1818
import org.opensearch.common.settings.Settings;
19+
import org.opensearch.ml.engine.tools.CatIndexTool;
1920
import org.opensearch.ml.rest.RestBaseAgentToolsIT;
2021
import org.opensearch.ml.utils.TestHelper;
2122

@@ -54,7 +55,7 @@ private void registerCatIndexFlowAgent() throws Exception {
5455
}
5556

5657
public void testCatIndexWithFewIndices() throws IOException {
57-
List<String> indices = createIndices(10);
58+
List<String> indices = createIndices(CatIndexTool.DEFAULT_PAGE_SIZE);
5859
Response response = TestHelper.makeRequest(client(), "POST", "/_plugins/_ml/agents/" + agentId + "/_execute", null, question, null);
5960
String responseStr = TestHelper.httpEntityToString(response.getEntity());
6061
String toolOutput = extractResult(responseStr);
@@ -67,7 +68,7 @@ public void testCatIndexWithFewIndices() throws IOException {
6768
}
6869

6970
public void testCatIndexWithMoreThan100Indices() throws IOException {
70-
List<String> indices = createIndices(101);
71+
List<String> indices = createIndices(CatIndexTool.DEFAULT_PAGE_SIZE + 1);
7172
Response response = TestHelper.makeRequest(client(), "POST", "/_plugins/_ml/agents/" + agentId + "/_execute", null, question, null);
7273
String responseStr = TestHelper.httpEntityToString(response.getEntity());
7374
String toolOutput = extractResult(responseStr);
@@ -79,6 +80,23 @@ public void testCatIndexWithMoreThan100Indices() throws IOException {
7980
}
8081
}
8182

83+
/**
84+
* An example of responseStr:
85+
* {
86+
* "inference_results": [
87+
* {
88+
* "output": [
89+
* {
90+
* "name": "response",
91+
* "result": "row,health,status,index,uuid,pri(number of primary shards),rep(number of replica shards),docs.count(number of available documents),docs.deleted(number of deleted documents),store.size(store size of primary and replica shards),pri.store.size(store size of primary shards)\n1,yellow,open,test4,6ohWskucQ3u3xV9tMjXCkA,1,1,0,0,208b,208b\n2,yellow,open,test5,5AQLe-Z3QKyyLibbZ3Xcng,1,1,0,0,208b,208b\n3,yellow,open,test2,66Cj3zjlQ-G8I3vWeEONpQ,1,1,0,0,208b,208b\n4,yellow,open,test3,6A-aVxPiTj2U9GnupHQ3BA,1,1,0,0,208b,208b\n5,yellow,open,test8,-WKw-SCET3aTFuWCMMixrw,1,1,0,0,208b,208b"
92+
* }
93+
* ]
94+
* }
95+
* ]
96+
* }
97+
* @param responseStr
98+
* @return
99+
*/
82100
private String extractResult(String responseStr) {
83101
JsonArray output = JsonParser
84102
.parseString(responseStr)

0 commit comments

Comments
 (0)