| 9 | |
| 10 | |
| 11 | class SoftwareDevDataset(BaseDataset): |
| 12 | def __init__(self): |
| 13 | data_file = os.path.join(DATA_PATH, "software_dev", SOFTWARE_DEV_FILE) |
| 14 | data = self.load(data_file) |
| 15 | super().__init__(data[:7]) |
| 16 | |
| 17 | self.metric_name = "Executability Metric" |
| 18 | self.metric_description = "Executability Metric is automatically scored by GPT-4 ranging from '1' to '4'. A score of '1' signifies complete failure, '2' denotes executable code, '3' represents largely satisfying expected workflow, and '4' indicates a perfect match with expectations." |
| 19 | |
| 20 | def __getitem__(self, idx: int) -> str: |
| 21 | """ |
| 22 | Retrieve a question by its index. |
| 23 | |
| 24 | Args: |
| 25 | idx (int): The index of the question. |
| 26 | |
| 27 | Returns: |
| 28 | str: The question text. |
| 29 | """ |
| 30 | return self.data[idx]["prompt"] |
| 31 | |
| 32 | def get_case_dict(self, idx: int): |
| 33 | """ |
| 34 | Create a dictionary representing a case at a specific index, including the ground truth if available. |
| 35 | |
| 36 | Args: |
| 37 | idx (int): The index of the case. |
| 38 | |
| 39 | Returns: |
| 40 | Dict[str, Any]: A dictionary with case details. |
| 41 | """ |
| 42 | try: |
| 43 | return { |
| 44 | "case_id": "software_dev_" + str(self.data[idx]["task_id"]), |
| 45 | "case_name": self.data[idx]["task_name"], |
| 46 | "task_id": "software_dev", |
| 47 | "task_description": self.data[idx]["task_description"] if "task_description" in self.data[idx] else self.data[idx]["prompt"], |
| 48 | "function_ids": "no use now", |
| 49 | "KB_id": "no use now", |
| 50 | "input": {"input_data": {"prompt": self.data[idx]["prompt"]}}, |
| 51 | "ground_truth": self.data[idx].get("answer", None), |
| 52 | "idx": idx, |
| 53 | "metric_name": self.metric_name, |
| 54 | "metric_description": self.metric_description, |
| 55 | } |
| 56 | except Exception as e: |
| 57 | print(f"Error: {e}, {self.data[idx]}") |
| 58 | raise e |
| 59 | |
| 60 | def evaluate(self, idx: int, answer: str): |
| 61 | """ |
| 62 | Evaluate the executability metric of the project code. |
| 63 | Args: |
| 64 | answer (str): The model-generated output for the text at the given index. |
| 65 | kwargs: Additional keyword arguments, (like index) which are not used in this method. |
| 66 | |
| 67 | Returns: |
| 68 | Dict[str, Any]: A dictionary containing evaluation results. |