| 97 | |
| 98 | |
| 99 | def get_answer(eg: dict, data_name: str): |
| 100 | if data_name in ["code_debug", "longbook_choice_eng"]: |
| 101 | OPTIONS = "ABCD" |
| 102 | if isinstance(eg["answer"], str): |
| 103 | ret = [eg["answer"], OPTIONS[eg['options'].index(eg["answer"])]] |
| 104 | elif isinstance(eg["answer"], list): |
| 105 | if len(eg["answer"]) == 1: |
| 106 | ret = [ |
| 107 | eg["answer"][0], |
| 108 | OPTIONS[eg['options'].index(eg["answer"][0])] |
| 109 | ] |
| 110 | elif len(eg["answer"]) == 2 and eg["answer"][1] in [ |
| 111 | 'A', 'B', 'C', 'D' |
| 112 | ]: |
| 113 | ret = eg['answer'] |
| 114 | else: |
| 115 | raise ValueError |
| 116 | else: |
| 117 | raise ValueError |
| 118 | return ret |
| 119 | |
| 120 | return eg["answer"] |
| 121 | |
| 122 | |
| 123 | def truncate_input(input, max_length, manner="middle"): |