Skip to content

Commit 9dc7b3e

Browse files
Fix: Ensure proper format for Bedrock deepseek tool result (#3933) (#3937)
* fix: deepseek function calling tool result * fix: unit test --------- (cherry picked from commit 3322ac5) Signed-off-by: Pavan Yekbote <pybot@amazon.com> Co-authored-by: Pavan Yekbote <pybot@amazon.com>
1 parent e50c7d7 commit 9dc7b3e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/function_calling/BedrockConverseDeepseekR1FunctionCalling.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public List<LLMMessage> supply(List<Map<String, Object>> toolResults) {
111111
if (toolUseId == null) {
112112
continue;
113113
}
114-
toolMessage.getContent().add(Map.of("text", Map.of(TOOL_CALL_ID, toolUseId, TOOL_RESULT, toolResult.get(TOOL_RESULT))));
114+
115+
String textJson = StringUtils.toJson(Map.of(TOOL_CALL_ID, toolUseId, TOOL_RESULT, toolResult.get(TOOL_RESULT)));
116+
toolMessage.getContent().add(Map.of("text", textJson));
115117
}
116118

117119
return List.of(toolMessage);

ml-algorithms/src/test/java/org/opensearch/ml/engine/function_calling/BedrockConverseDeepseekR1FunctionCallingTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.opensearch.ml.engine.function_calling;
77

8-
import static org.junit.Assert.*;
98
import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_INTERFACE_BEDROCK_CONVERSE_DEEPSEEK_R1;
109
import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.LLM_RESPONSE_FILTER;
1110
import static org.opensearch.ml.engine.algorithms.agent.AgentUtils.TOOL_CALL_ID;
@@ -29,6 +28,7 @@
2928
import org.opensearch.ml.common.output.model.ModelTensor;
3029
import org.opensearch.ml.common.output.model.ModelTensorOutput;
3130
import org.opensearch.ml.common.output.model.ModelTensors;
31+
import org.opensearch.ml.common.utils.StringUtils;
3232
import org.opensearch.ml.repackage.com.google.common.collect.ImmutableMap;
3333

3434
public class BedrockConverseDeepseekR1FunctionCallingTests {
@@ -77,8 +77,11 @@ public void supply() {
7777
Assert.assertEquals(1, messages.size());
7878
LLMMessage message = messages.get(0);
7979
Assert.assertEquals("user", message.getRole());
80-
List<Map<String, Map<String, String>>> content = (List<Map<String, Map<String, String>>>) message.getContent();
81-
Assert.assertEquals("test_tool_call_id", content.get(0).get("text").get(TOOL_CALL_ID));
82-
Assert.assertEquals("test result for bedrock deepseek", content.get(0).get("text").get(TOOL_RESULT));
80+
List<Object> content = (List<Object>) message.getContent();
81+
Map<String, String> textMap = (Map<String, String>) content.get(0);
82+
String textJson = textMap.get("text");
83+
Map<String, Object> resultMap = StringUtils.fromJson(textJson, "response");
84+
Assert.assertEquals("test_tool_call_id", resultMap.get("tool_call_id"));
85+
Assert.assertEquals("test result for bedrock deepseek", resultMap.get("tool_result"));
8386
}
8487
}

0 commit comments

Comments
 (0)