|
8 | 8 | import static org.opensearch.ml.common.conversation.ActionConstants.ADDITIONAL_INFO_FIELD;
|
9 | 9 | import static org.opensearch.ml.common.conversation.ActionConstants.AI_RESPONSE_FIELD;
|
10 | 10 | import static org.opensearch.ml.common.utils.StringUtils.gson;
|
11 |
| -import static org.opensearch.ml.common.utils.StringUtils.toUTF8; |
12 | 11 | import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.extractModelResponseJson;
|
13 | 12 |
|
14 | 13 | import java.security.AccessController;
|
@@ -546,7 +545,13 @@ private void runReAct(
|
546 | 545 | .singletonList(
|
547 | 546 | ModelTensor
|
548 | 547 | .builder()
|
549 |
| - .dataAsMap(ImmutableMap.of("response", lastThought.get() + "\nObservation: " + outputToOutputString(output))) |
| 548 | + .dataAsMap( |
| 549 | + ImmutableMap |
| 550 | + .of( |
| 551 | + "response", |
| 552 | + lastThought.get() + "\nObservation: " + outputToOutputString(output) |
| 553 | + ) |
| 554 | + ) |
550 | 555 | .build()
|
551 | 556 | )
|
552 | 557 | )
|
@@ -654,22 +659,17 @@ private void runReAct(
|
654 | 659 |
|
655 | 660 | private String outputToOutputString(Object output) throws PrivilegedActionException {
|
656 | 661 | String outputString;
|
657 |
| - if (output instanceof ModelTensorOutput) |
658 |
| - { |
| 662 | + if (output instanceof ModelTensorOutput) { |
659 | 663 | ModelTensor outputModel = ((ModelTensorOutput) output).getMlModelOutputs().get(0).getMlModelTensors().get(0);
|
660 |
| - if (outputModel.getDataAsMap() != null) |
661 |
| - { |
662 |
| - outputString = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> gson.toJson(outputModel.getDataAsMap())); |
663 |
| - } |
664 |
| - else { |
| 664 | + if (outputModel.getDataAsMap() != null) { |
| 665 | + outputString = AccessController |
| 666 | + .doPrivileged((PrivilegedExceptionAction<String>) () -> gson.toJson(outputModel.getDataAsMap())); |
| 667 | + } else { |
665 | 668 | outputString = outputModel.getResult();
|
666 | 669 | }
|
667 |
| - } |
668 |
| - else if (output instanceof String) |
669 |
| - { |
| 670 | + } else if (output instanceof String) { |
670 | 671 | outputString = (String) output;
|
671 |
| - } |
672 |
| - else { |
| 672 | + } else { |
673 | 673 | outputString = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> gson.toJson(output));
|
674 | 674 | }
|
675 | 675 | return outputString;
|
|
0 commit comments