|
1 | 1 | import pytest |
2 | 2 | import base64 |
3 | 3 |
|
4 | | -from haystack.dataclasses import StreamingChunk |
| 4 | +from haystack.dataclasses import ComponentInfo, StreamingChunk |
5 | 5 | from haystack.tools import Tool |
6 | 6 | from haystack_integrations.components.generators.amazon_bedrock.chat.utils import ( |
7 | 7 | _format_tools, |
|
15 | 15 | ) |
16 | 16 | from haystack_experimental.dataclasses.chat_message import ChatMessage, ChatRole, ToolCall, ImageContent |
17 | 17 |
|
18 | | - |
19 | 18 | # NOTE: original module and tests |
20 | 19 | def weather(city: str): |
21 | 20 | """Get weather for a given city.""" |
@@ -346,6 +345,9 @@ def test_process_streaming_response_one_tool_call(self, mock_boto3_session): |
346 | 345 | Test that process_streaming_response correctly handles streaming events and accumulates responses |
347 | 346 | """ |
348 | 347 | model = "anthropic.claude-3-5-sonnet-20240620-v1:0" |
| 348 | + type_ = ( |
| 349 | + "haystack_integrations.components.generators.amazon_bedrock.chat.chat_generator.AmazonBedrockChatGenerator" |
| 350 | + ) |
349 | 351 | streaming_chunks = [] |
350 | 352 |
|
351 | 353 | def test_callback(chunk: StreamingChunk): |
@@ -386,7 +388,11 @@ def test_callback(chunk: StreamingChunk): |
386 | 388 | }, |
387 | 389 | ] |
388 | 390 |
|
389 | | - replies = _parse_streaming_response(events, test_callback, model) |
| 391 | + component_info = ComponentInfo( |
| 392 | + type=type_, |
| 393 | + ) |
| 394 | + |
| 395 | + replies = _parse_streaming_response(events, test_callback, model, component_info) |
390 | 396 | # Pop completion_start_time since it will always change |
391 | 397 | replies[0].meta.pop("completion_start_time") |
392 | 398 | expected_messages = [ |
@@ -421,12 +427,19 @@ def test_callback(chunk: StreamingChunk): |
421 | 427 | } |
422 | 428 | ] |
423 | 429 |
|
| 430 | + for chunk in streaming_chunks: |
| 431 | + assert chunk.component_info.type == type_ |
| 432 | + assert chunk.component_info.name is None # not in a pipeline |
| 433 | + |
424 | 434 | # Verify final replies |
425 | 435 | assert len(replies) == 1 |
426 | 436 | assert replies == expected_messages |
427 | 437 |
|
428 | 438 | def test_parse_streaming_response_with_two_tool_calls(self, mock_boto3_session): |
429 | 439 | model = "anthropic.claude-3-5-sonnet-20240620-v1:0" |
| 440 | + type_ = ( |
| 441 | + "haystack_integrations.components.generators.amazon_bedrock.chat.chat_generator.AmazonBedrockChatGenerator" |
| 442 | + ) |
430 | 443 | streaming_chunks = [] |
431 | 444 |
|
432 | 445 | def test_callback(chunk: StreamingChunk): |
@@ -475,7 +488,11 @@ def test_callback(chunk: StreamingChunk): |
475 | 488 | }, |
476 | 489 | ] |
477 | 490 |
|
478 | | - replies = _parse_streaming_response(events, test_callback, model) |
| 491 | + component_info = ComponentInfo( |
| 492 | + type=type_, |
| 493 | + ) |
| 494 | + |
| 495 | + replies = _parse_streaming_response(events, test_callback, model, component_info) |
479 | 496 | # Pop completion_start_time since it will always change |
480 | 497 | replies[0].meta.pop("completion_start_time") |
481 | 498 | expected_messages = [ |
|
0 commit comments