@@ -1583,29 +1583,6 @@ def test_chat_completion_streaming_with_tools(
15831583 }
15841584]
15851585
1586- DATA_COLLECTION_TEXT_GENERATION_EXPECTED_VALUES = {
1587- SPANDATA .GEN_AI_REQUEST_MESSAGES : "Hello" ,
1588- SPANDATA .GEN_AI_RESPONSE_TEXT : "[mocked] Hello! How can i help you?" ,
1589- }
1590-
1591- DATA_COLLECTION_TEXT_GENERATION_STREAMING_EXPECTED_VALUES = {
1592- SPANDATA .GEN_AI_REQUEST_MESSAGES : "Hello" ,
1593- SPANDATA .GEN_AI_RESPONSE_TEXT : "the mocked model response" ,
1594- }
1595-
1596- DATA_COLLECTION_CHAT_COMPLETION_TOOLS_EXPECTED_VALUES = {
1597- SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS : '[{"type": "function", "function": {"name": "get_weather", "description": "Get current weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}}]' ,
1598- SPANDATA .GEN_AI_REQUEST_MESSAGES : '[{"role": "user", "content": "What is the weather in Paris?"}]' ,
1599- SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS : '[{"function": {"arguments": {"location": "Paris"}, "name": "get_weather", "description": "None"}, "id": "call_123", "type": "function"}]' ,
1600- }
1601-
1602- DATA_COLLECTION_CHAT_COMPLETION_STREAMING_TOOLS_EXPECTED_VALUES = {
1603- SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS : '[{"type": "function", "function": {"name": "get_weather", "description": "Get current weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}}]' ,
1604- SPANDATA .GEN_AI_REQUEST_MESSAGES : '[{"role": "user", "content": "What is the weather in Paris?"}]' ,
1605- SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS : '[{"function": {"arguments": {"location": "Paris"}, "name": "get_weather"}, "id": "call_123", "type": "function", "index": "None"}]' ,
1606- SPANDATA .GEN_AI_RESPONSE_TEXT : "response with tool calls follows" ,
1607- }
1608-
16091586
16101587@pytest .mark .parametrize ("stream_gen_ai_spans" , [True , False ])
16111588@pytest .mark .httpx_mock (assert_all_requests_were_expected = False )
@@ -1738,9 +1715,14 @@ def test_text_generation_data_collection(
17381715 (span ,) = [sp for sp in transaction ["spans" ] if sp ["op" ].startswith ("gen_ai" )]
17391716 span_data = span ["data" ]
17401717
1718+ expected_values = {
1719+ SPANDATA .GEN_AI_REQUEST_MESSAGES : "Hello" ,
1720+ SPANDATA .GEN_AI_RESPONSE_TEXT : "[mocked] Hello! How can i help you?" ,
1721+ }
1722+
17411723 for key in expected_present :
17421724 assert key in span_data , f"{ key } should have been collected"
1743- assert span_data [key ] == DATA_COLLECTION_TEXT_GENERATION_EXPECTED_VALUES [key ]
1725+ assert span_data [key ] == expected_values [key ]
17441726
17451727 for key in expected_absent :
17461728 assert key not in span_data , f"{ key } should not have been collected"
@@ -1884,12 +1866,14 @@ def test_text_generation_streaming_data_collection(
18841866 (span ,) = [sp for sp in transaction ["spans" ] if sp ["op" ].startswith ("gen_ai" )]
18851867 span_data = span ["data" ]
18861868
1869+ expected_values = {
1870+ SPANDATA .GEN_AI_REQUEST_MESSAGES : "Hello" ,
1871+ SPANDATA .GEN_AI_RESPONSE_TEXT : "the mocked model response" ,
1872+ }
1873+
18871874 for key in expected_present :
18881875 assert key in span_data , f"{ key } should have been collected"
1889- assert (
1890- span_data [key ]
1891- == DATA_COLLECTION_TEXT_GENERATION_STREAMING_EXPECTED_VALUES [key ]
1892- )
1876+ assert span_data [key ] == expected_values [key ]
18931877
18941878 for key in expected_absent :
18951879 assert key not in span_data , f"{ key } should not have been collected"
@@ -2043,11 +2027,15 @@ def test_chat_completion_data_collection_tools(
20432027 (span ,) = [sp for sp in transaction ["spans" ] if sp ["op" ].startswith ("gen_ai" )]
20442028 span_data = span ["data" ]
20452029
2030+ expected_values = {
2031+ SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS : '[{"type": "function", "function": {"name": "get_weather", "description": "Get current weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}}]' ,
2032+ SPANDATA .GEN_AI_REQUEST_MESSAGES : '[{"role": "user", "content": "What is the weather in Paris?"}]' ,
2033+ SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS : '[{"function": {"arguments": {"location": "Paris"}, "name": "get_weather", "description": "None"}, "id": "call_123", "type": "function"}]' ,
2034+ }
2035+
20462036 for key in expected_present :
20472037 assert key in span_data , f"{ key } should have been collected"
2048- assert (
2049- span_data [key ] == DATA_COLLECTION_CHAT_COMPLETION_TOOLS_EXPECTED_VALUES [key ]
2050- )
2038+ assert span_data [key ] == expected_values [key ]
20512039
20522040 for key in expected_absent :
20532041 assert key not in span_data , f"{ key } should not have been collected"
@@ -2217,12 +2205,16 @@ def test_chat_completion_streaming_data_collection_tools(
22172205 (span ,) = [sp for sp in transaction ["spans" ] if sp ["op" ].startswith ("gen_ai" )]
22182206 span_data = span ["data" ]
22192207
2208+ expected_values = {
2209+ SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS : '[{"type": "function", "function": {"name": "get_weather", "description": "Get current weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}}]' ,
2210+ SPANDATA .GEN_AI_REQUEST_MESSAGES : '[{"role": "user", "content": "What is the weather in Paris?"}]' ,
2211+ SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS : '[{"function": {"arguments": {"location": "Paris"}, "name": "get_weather"}, "id": "call_123", "type": "function", "index": "None"}]' ,
2212+ SPANDATA .GEN_AI_RESPONSE_TEXT : "response with tool calls follows" ,
2213+ }
2214+
22202215 for key in expected_present :
22212216 assert key in span_data , f"{ key } should have been collected"
2222- assert (
2223- span_data [key ]
2224- == DATA_COLLECTION_CHAT_COMPLETION_STREAMING_TOOLS_EXPECTED_VALUES [key ]
2225- )
2217+ assert span_data [key ] == expected_values [key ]
22262218
22272219 for key in expected_absent :
22282220 assert key not in span_data , f"{ key } should not have been collected"
0 commit comments