@@ -1458,60 +1458,6 @@ def test_generate_content_with_content_object(
14581458 ]
14591459
14601460
1461- def test_generate_content_with_conversation_history (
1462- sentry_init , capture_events , mock_genai_client
1463- ):
1464- """Test generate_content with list of Content objects (conversation history)."""
1465- sentry_init (
1466- integrations = [GoogleGenAIIntegration (include_prompts = True )],
1467- traces_sample_rate = 1.0 ,
1468- send_default_pii = True ,
1469- )
1470- events = capture_events ()
1471-
1472- mock_http_response = create_mock_http_response (EXAMPLE_API_RESPONSE_JSON )
1473-
1474- # Create conversation history
1475- contents = [
1476- genai_types .Content (
1477- role = "user" , parts = [genai_types .Part (text = "What is the capital of France?" )]
1478- ),
1479- genai_types .Content (
1480- role = "model" ,
1481- parts = [genai_types .Part (text = "The capital of France is Paris." )],
1482- ),
1483- genai_types .Content (
1484- role = "user" , parts = [genai_types .Part (text = "What about Germany?" )]
1485- ),
1486- ]
1487-
1488- with mock .patch .object (
1489- mock_genai_client ._api_client , "request" , return_value = mock_http_response
1490- ):
1491- with start_transaction (name = "google_genai" ):
1492- mock_genai_client .models .generate_content (
1493- model = "gemini-1.5-flash" , contents = contents , config = create_test_config ()
1494- )
1495-
1496- (event ,) = events
1497- invoke_span = event ["spans" ][0 ]
1498-
1499- messages = json .loads (invoke_span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1500- assert len (messages ) == 3
1501- assert messages [0 ]["role" ] == "user"
1502- assert messages [0 ]["content" ] == [
1503- {"text" : "What is the capital of France?" , "type" : "text" }
1504- ]
1505- assert (
1506- messages [1 ]["role" ] == "assistant"
1507- ) # "model" should be normalized to "assistant"
1508- assert messages [1 ]["content" ] == [
1509- {"text" : "The capital of France is Paris." , "type" : "text" }
1510- ]
1511- assert messages [2 ]["role" ] == "user"
1512- assert messages [2 ]["content" ] == [{"text" : "What about Germany?" , "type" : "text" }]
1513-
1514-
15151461def test_generate_content_with_dict_format (
15161462 sentry_init , capture_events , mock_genai_client
15171463):
@@ -1681,17 +1627,12 @@ def test_generate_content_with_function_response(
16811627 invoke_span = event ["spans" ][0 ]
16821628
16831629 messages = json .loads (invoke_span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1684- assert len (messages ) == 2
1630+ assert len (messages ) == 1
16851631 # First message is user message
1686- assert messages [0 ]["role" ] == "user"
1687- assert messages [0 ]["content" ] == [
1688- {"text" : "What's the weather in Paris?" , "type" : "text" }
1689- ]
1690- # Second message is tool message
1691- assert messages [1 ]["role" ] == "tool"
1692- assert messages [1 ]["content" ]["toolCallId" ] == "call_123"
1693- assert messages [1 ]["content" ]["toolName" ] == "get_weather"
1694- assert messages [1 ]["content" ]["output" ] == '"Sunny, 72F"'
1632+ assert messages [0 ]["role" ] == "tool"
1633+ assert messages [0 ]["content" ]["toolCallId" ] == "call_123"
1634+ assert messages [0 ]["content" ]["toolName" ] == "get_weather"
1635+ assert messages [0 ]["content" ]["output" ] == '"Sunny, 72F"'
16951636
16961637
16971638def test_generate_content_with_mixed_string_and_content (
@@ -1732,18 +1673,10 @@ def test_generate_content_with_mixed_string_and_content(
17321673 invoke_span = event ["spans" ][0 ]
17331674
17341675 messages = json .loads (invoke_span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1735- assert len (messages ) == 3
1736- # String becomes user message
1737- assert messages [0 ]["role" ] == "user"
1738- assert messages [0 ]["content" ] == "Hello, this is a string message"
1739- # Model role normalized to assistant
1740- assert messages [1 ]["role" ] == "assistant"
1741- assert messages [1 ]["content" ] == [
1742- {"text" : "Hi! How can I help you?" , "type" : "text" }
1743- ]
1676+ assert len (messages ) == 1
17441677 # User message
1745- assert messages [2 ]["role" ] == "user"
1746- assert messages [2 ]["content" ] == [{"text" : "Tell me a joke" , "type" : "text" }]
1678+ assert messages [0 ]["role" ] == "user"
1679+ assert messages [0 ]["content" ] == [{"text" : "Tell me a joke" , "type" : "text" }]
17471680
17481681
17491682def test_generate_content_with_part_object_directly (
@@ -1811,13 +1744,9 @@ def test_generate_content_with_list_of_dicts(
18111744 invoke_span = event ["spans" ][0 ]
18121745
18131746 messages = json .loads (invoke_span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1814- assert len (messages ) == 3
1747+ assert len (messages ) == 1
18151748 assert messages [0 ]["role" ] == "user"
1816- assert messages [0 ]["content" ] == [{"text" : "First user message" , "type" : "text" }]
1817- assert messages [1 ]["role" ] == "assistant"
1818- assert messages [1 ]["content" ] == [{"text" : "First model response" , "type" : "text" }]
1819- assert messages [2 ]["role" ] == "user"
1820- assert messages [2 ]["content" ] == [{"text" : "Second user message" , "type" : "text" }]
1749+ assert messages [0 ]["content" ] == [{"text" : "Second user message" , "type" : "text" }]
18211750
18221751
18231752def test_generate_content_with_dict_inline_data (
0 commit comments