GeezerVison is showing github.com — fix: GenAI Client(evals) - Show intermediate_events as a conversation… · hamgor/python-aiplatform@4d4ac8a
File treeExpand file treeCollapse file tree Open diff view settings tests/unit/agentplatform/genai
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: agentplatform/_genai/_evals_visualization.py +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -229,6 +229,20 @@ def _extract_dataset_rows(dataset: types.EvaluationDataset) -> list[dict[str, An | 229 | 229 | } | 230 | 230 | processed_rows.append(processed_row) | 231 | 231 |
| | 232 | + for row in processed_rows: | | 233 | + if isinstance(row["agent_data"], str) or not isinstance( | | 234 | + row["intermediate_events"], str | | 235 | + ): | | 236 | + continue | | 237 | + try: | | 238 | + events = json.loads(row["intermediate_events"]) | | 239 | + except json.JSONDecodeError: | | 240 | + continue | | 241 | + if isinstance(events, list) and events: | | 242 | + row["agent_data"] = json.dumps( | | 243 | + {"turns": [{"turn_index": 0, "events": events}]}, ensure_ascii=False | | 244 | + ) | | 245 | + | 232 | 246 | return processed_rows | 233 | 247 |
| 234 | 248 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/agentplatform/genai/test_evals.py +13-3Lines changed: 13 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2382,13 +2382,20 @@ def test_display_evaluation_result_with_agent_trace_prefixes(self, mock_is_ipyth | 2382 | 2382 | } | 2383 | 2383 | }, | 2384 | 2384 | ] | | 2385 | + agent_data = {"turns": [{"turn_index": 3, "turn_id": "t3", "events": []}]} | 2385 | 2386 | dataset_df = pd.DataFrame( | 2386 | 2387 | [ | 2387 | 2388 | { | 2388 | 2389 | "prompt": "Test prompt", | 2389 | 2390 | "response": "Test response", | 2390 | 2391 | "intermediate_events": intermediate_events_list, | 2391 | 2392 | }, | | 2393 | + { | | 2394 | + "prompt": "Test prompt 2", | | 2395 | + "response": "Test response 2", | | 2396 | + "intermediate_events": intermediate_events_list, | | 2397 | + "agent_data": agent_data, | | 2398 | + }, | 2392 | 2399 | ] | 2393 | 2400 | ) | 2394 | 2401 | eval_dataset = agentplatform_genai_types.EvaluationDataset( | @@ -2415,9 +2422,12 @@ def test_display_evaluation_result_with_agent_trace_prefixes(self, mock_is_ipyth | 2415 | 2422 | html_content = mock_display_module.HTML.call_args[0][0] | 2416 | 2423 | match = re.search(r'atob\("([^"]+)"\)', html_content) | 2417 | 2424 | assert match | 2418 | | - decoded_json = base64.b64decode(match.group(1)).decode("utf-8") | 2419 | | - assert "my_function" in decoded_json | 2420 | | - assert "this is model response" in decoded_json | | 2425 | + payload = json.loads(base64.b64decode(match.group(1)).decode("utf-8")) | | 2426 | + rows = payload["metadata"]["dataset"] | | 2427 | + assert json.loads(rows[0]["agent_data"]) == { | | 2428 | + "turns": [{"turn_index": 0, "events": intermediate_events_list}] | | 2429 | + } | | 2430 | + assert json.loads(rows[1]["agent_data"]) == agent_data | 2421 | 2431 |
| 2422 | 2432 | del sys.modules["IPython"] | 2423 | 2433 | del sys.modules["IPython.display"] | |
Collapse file Copy file name to clipboardExpand all lines: vertexai/_genai/_evals_visualization.py +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -228,6 +228,20 @@ def _extract_dataset_rows(dataset: types.EvaluationDataset) -> list[dict[str, An | 228 | 228 | } | 229 | 229 | processed_rows.append(processed_row) | 230 | 230 |
| | 231 | + for row in processed_rows: | | 232 | + if isinstance(row["agent_data"], str) or not isinstance( | | 233 | + row["intermediate_events"], str | | 234 | + ): | | 235 | + continue | | 236 | + try: | | 237 | + events = json.loads(row["intermediate_events"]) | | 238 | + except json.JSONDecodeError: | | 239 | + continue | | 240 | + if isinstance(events, list) and events: | | 241 | + row["agent_data"] = json.dumps( | | 242 | + {"turns": [{"turn_index": 0, "events": events}]}, ensure_ascii=False | | 243 | + ) | | 244 | + | 231 | 245 | return processed_rows | 232 | 246 |
| 233 | 247 |
| |
|