|
17 | 17 | from haystack.tools import Tool |
18 | 18 |
|
19 | 19 | from haystack_integrations.components.generators.amazon_bedrock.chat.utils import ( |
| 20 | + _convert_event_to_streaming_chunk, |
20 | 21 | _convert_file_content_to_bedrock_format, |
21 | 22 | _convert_streaming_chunks_to_chat_message, |
22 | 23 | _format_messages, |
@@ -2099,3 +2100,42 @@ def test_validate_and_format_cache_point(self): |
2099 | 2100 |
|
2100 | 2101 | with pytest.raises(ValueError, match=r"Cache point can only contain 'type' and 'ttl' keys."): |
2101 | 2102 | _validate_and_format_cache_point({"type": "default", "invalid": "config"}) |
| 2103 | + |
| 2104 | + def test_convert_event_to_streaming_chunk_tool_use_input_int(self): |
| 2105 | + model = "global.anthropic.claude-sonnet-4-6" |
| 2106 | + component_info = ComponentInfo( |
| 2107 | + type="haystack_integrations.components.generators.amazon_bedrock.chat.chat_generator.AmazonBedrockChatGenerator" |
| 2108 | + ) |
| 2109 | + |
| 2110 | + # boto3 may return an int for toolUse input — must be cast to str |
| 2111 | + event_int = { |
| 2112 | + "contentBlockDelta": { |
| 2113 | + "delta": {"toolUse": {"input": 42}}, |
| 2114 | + "contentBlockIndex": 1, |
| 2115 | + } |
| 2116 | + } |
| 2117 | + chunk = _convert_event_to_streaming_chunk(event_int, model, component_info) |
| 2118 | + assert chunk.tool_calls is not None |
| 2119 | + assert chunk.tool_calls[0].arguments == "42" |
| 2120 | + |
| 2121 | + # None input should stay None |
| 2122 | + event_none = { |
| 2123 | + "contentBlockDelta": { |
| 2124 | + "delta": {"toolUse": {"input": None}}, |
| 2125 | + "contentBlockIndex": 1, |
| 2126 | + } |
| 2127 | + } |
| 2128 | + chunk = _convert_event_to_streaming_chunk(event_none, model, component_info) |
| 2129 | + assert chunk.tool_calls is not None |
| 2130 | + assert chunk.tool_calls[0].arguments is None |
| 2131 | + |
| 2132 | + # Normal string input should pass through unchanged |
| 2133 | + event_str = { |
| 2134 | + "contentBlockDelta": { |
| 2135 | + "delta": {"toolUse": {"input": '{"city": "Berlin"}'}}, |
| 2136 | + "contentBlockIndex": 1, |
| 2137 | + } |
| 2138 | + } |
| 2139 | + chunk = _convert_event_to_streaming_chunk(event_str, model, component_info) |
| 2140 | + assert chunk.tool_calls is not None |
| 2141 | + assert chunk.tool_calls[0].arguments == '{"city": "Berlin"}' |
0 commit comments