@@ -160,3 +160,69 @@ def test_tracing_file_to_evalset():
160160 )
161161
162162 os .remove (tracing_file_path )
163+
164+
165+ def test_tracing_file_creates_isolated_eval_case_per_sorted_trace (tmp_path ):
166+ trace_a = 101
167+ trace_b = 202
168+
169+ def call_llm (trace_id , start_time , app_name , user_id , prompt = "" , completion = "" ):
170+ return {
171+ "name" : "call_llm" ,
172+ "trace_id" : trace_id ,
173+ "start_time" : start_time ,
174+ "attributes" : {
175+ "gen_ai.app.name" : app_name ,
176+ "gen_ai.user.id" : user_id ,
177+ "gen_ai.prompt.0.content" : prompt ,
178+ "gen_ai.completion.0.content" : completion ,
179+ },
180+ }
181+
182+ def execute_tool (start_time , tool_name ):
183+ return {
184+ "name" : f"execute_tool { tool_name } " ,
185+ "trace_id" : trace_a ,
186+ "start_time" : start_time ,
187+ "attributes" : {
188+ "gen_ai.tool.name" : tool_name ,
189+ "gen_ai.tool.input" : json .dumps ({"parameters" : {"order" : tool_name }}),
190+ "gen_ai.tool.output" : json .dumps ({"id" : f"call-{ tool_name } " }),
191+ },
192+ }
193+
194+ tracing_data = [
195+ call_llm (trace_a , 40 , "app-a" , "user-a" , completion = "answer-a" ),
196+ call_llm (trace_b , 60 , "app-b" , "user-b" , completion = "answer-b" ),
197+ execute_tool (30 , "second" ),
198+ call_llm (trace_b , 50 , "app-b" , "user-b" , prompt = "question-b" ),
199+ call_llm (trace_a , 10 , "app-a" , "user-a" , prompt = "question-a" ),
200+ execute_tool (20 , "first" ),
201+ ]
202+ tracing_file_path = tmp_path / "tracing.json"
203+ tracing_file_path .write_text (json .dumps (tracing_data ))
204+
205+ eval_set = BaseEvaluator (
206+ agent = None , name = "test_evaluator"
207+ )._build_eval_set_from_tracing_json (str (tracing_file_path ))
208+
209+ assert len (eval_set .eval_cases ) == 2
210+ eval_cases = {
211+ eval_case .session_input .app_name : eval_case for eval_case in eval_set .eval_cases
212+ }
213+
214+ case_a = eval_cases ["app-a" ]
215+ assert case_a .session_input .user_id == "user-a"
216+ assert case_a .creation_timestamp == 10 / 1e9
217+ assert case_a .conversation [0 ].user_content .parts [0 ].text == "question-a"
218+ assert case_a .conversation [0 ].final_response .parts [0 ].text == "answer-a"
219+ assert [
220+ tool .name for tool in case_a .conversation [0 ].intermediate_data .tool_uses
221+ ] == ["first" , "second" ]
222+
223+ case_b = eval_cases ["app-b" ]
224+ assert case_b .session_input .user_id == "user-b"
225+ assert case_b .creation_timestamp == 50 / 1e9
226+ assert case_b .conversation [0 ].user_content .parts [0 ].text == "question-b"
227+ assert case_b .conversation [0 ].final_response .parts [0 ].text == "answer-b"
228+ assert case_b .conversation [0 ].intermediate_data .tool_uses == []
0 commit comments