27
27
import org .opensearch .ml .common .transport .connector .MLConnectorSearchAction ;
28
28
import org .opensearch .ml .common .transport .model .MLModelSearchAction ;
29
29
import org .opensearch .ml .common .transport .model_group .MLModelGroupSearchAction ;
30
- import org .opensearch .ml .common .utils .StringUtils ;
31
30
import org .opensearch .search .SearchHit ;
32
31
import org .opensearch .search .builder .SearchSourceBuilder ;
33
32
import org .opensearch .transport .client .Client ;
34
33
34
+ import com .google .gson .Gson ;
35
+ import com .google .gson .GsonBuilder ;
35
36
import com .google .gson .JsonElement ;
36
37
import com .google .gson .JsonObject ;
37
38
@@ -62,6 +63,8 @@ public class SearchIndexTool implements Tool {
62
63
+ "Invalid value: \\ n{\\ \" match\\ \" :{\\ \" population_description\\ \" :\\ \" seattle 2023 population\\ \" }}\\ nThe value is invalid because the match not wrapped by \\ \" query\\ \" .\" ,"
63
64
+ "\" additionalProperties\" :false}},\" required\" :[\" index\" ,\" query\" ],\" additionalProperties\" :false}" ;
64
65
66
+ private static final Gson GSON = new GsonBuilder ().serializeSpecialFloatingPointValues ().create ();
67
+
65
68
private String name = TYPE ;
66
69
private Map <String , Object > attributes ;
67
70
private String description = DEFAULT_DESCRIPTION ;
@@ -114,7 +117,7 @@ private static Map<String, Object> processResponse(SearchHit hit) {
114
117
public <T > void run (Map <String , String > parameters , ActionListener <T > listener ) {
115
118
try {
116
119
String input = parameters .get (INPUT_FIELD );
117
- JsonObject jsonObject = StringUtils . gson .fromJson (input , JsonObject .class );
120
+ JsonObject jsonObject = GSON .fromJson (input , JsonObject .class );
118
121
String index = Optional .ofNullable (jsonObject ).map (x -> x .get (INDEX_FIELD )).map (JsonElement ::getAsString ).orElse (null );
119
122
String query = Optional .ofNullable (jsonObject ).map (x -> x .get (QUERY_FIELD )).map (JsonElement ::toString ).orElse (null );
120
123
if (index == null || query == null ) {
@@ -131,7 +134,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
131
134
for (SearchHit hit : hits ) {
132
135
String doc = AccessController .doPrivileged ((PrivilegedExceptionAction <String >) () -> {
133
136
Map <String , Object > docContent = processResponse (hit );
134
- return StringUtils . gson .toJson (docContent );
137
+ return GSON .toJson (docContent );
135
138
});
136
139
contextBuilder .append (doc ).append ("\n " );
137
140
}
0 commit comments