Skip to content

Commit

Permalink
add logs for debug
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Jan 15, 2025
1 parent e8e2f24 commit 9805493
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/test/java/org/opensearch/integTest/BaseAgentToolsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ protected void updateClusterSettings(String settingKey, Object value) {
@SneakyThrows
private Map<String, Object> parseResponseToMap(Response response) {
String responseBody = EntityUtils.toString(response.getEntity());
logger.info("responseBody: {}", responseBody);
Map<String, Object> responseInMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), responseBody, false);
return responseInMap;
try {
return XContentHelper.convertToMap(XContentType.JSON.xContent(), responseBody, false);
} catch (Exception e) {
logger.error("failed to parse response to map: {}", responseBody, e);
return Collections.emptyMap();
}
}

@SneakyThrows
Expand Down Expand Up @@ -338,8 +341,11 @@ private String parseStringResponseFromExecuteAgentResponse(Response response) {

// execute the agent, and return the String response from the json structure
// {"inference_results": [{"output": [{"name": "response","result": "the result to return."}]}]}
@SneakyThrows
public String executeAgent(String agentId, String requestBody) {
Response response = makeRequest(client(), "POST", "/_plugins/_ml/agents/" + agentId + "/_execute", null, requestBody, null);
String responseBody = EntityUtils.toString(response.getEntity());
logger.info("responseBody for agent execution: {}, agentId: {}", responseBody, agentId);
return parseStringResponseFromExecuteAgentResponse(response);
}

Expand Down

0 comments on commit 9805493

Please sign in to comment.