MCPcopy
hub / github.com/agent-infra/sandbox / parse

Method parse

evaluation/dataset_parser.py:35–77  ·  view source on GitHub ↗

Parse XML evaluation file and return list of evaluation tasks. Supports both and tags. Prefers if both exist. Args: file_path: Path to XML evaluation file Returns: List of evaluation tasks wi

(self, file_path: Path)

Source from the content-addressed store, hash-verified

33 """Parser for XML evaluation dataset files."""
34
35 def parse(self, file_path: Path) -> List[Dict[str, Any]]:
36 """
37 Parse XML evaluation file and return list of evaluation tasks.
38
39 Supports both <response> and <response_pattern> tags.
40 Prefers <response> if both exist.
41
42 Args:
43 file_path: Path to XML evaluation file
44
45 Returns:
46 List of evaluation tasks with "prompt" and "response" keys
47 """
48 try:
49 tree = ET.parse(file_path)
50 root = tree.getroot()
51 evaluations = []
52
53 tasks = root.findall(".//task")
54 for task in tasks:
55 prompt_elem = task.find("prompt")
56 response_elem = task.find("response")
57 response_pattern_elem = task.find("response_pattern")
58
59 # Support both <response> and <response_pattern>
60 # Prefer <response> if both exist
61 expected_response = None
62 if response_elem is not None:
63 expected_response = (response_elem.text or "").strip()
64 elif response_pattern_elem is not None:
65 expected_response = (response_pattern_elem.text or "").strip()
66
67 if prompt_elem is not None and expected_response is not None:
68 eval_dict = {
69 "prompt": (prompt_elem.text or "").strip(),
70 "response": expected_response,
71 }
72 evaluations.append(eval_dict)
73
74 return evaluations
75 except Exception as e:
76 print(f"Error parsing evaluation file {file_path}: {e}")
77 return []

Callers 3

run_evaluationFunction · 0.95
getApigTriggerMethod · 0.45
fromJsonFunction · 0.45

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected