(generation)
| 107 | return 1.0 if grade_answer(answer, ground_truth) else 0.0 |
| 108 | |
| 109 | def match(generation): |
| 110 | pattern = r"<type>(.*?)</type>.*?<question>(.*?)</question>.*?<answer>(.*?)</answer>" |
| 111 | match = re.search(pattern, generation, re.DOTALL) |
| 112 | |
| 113 | if match: |
| 114 | result = { |
| 115 | "type": match.group(1).strip(), |
| 116 | "question": match.group(2).strip(), |
| 117 | "answer": match.group(3).strip() |
| 118 | } |
| 119 | return result |
| 120 | |
| 121 | def generate_temp_filename(prefix="temp", suffix=".json"): |
| 122 | timestamp = int(time.time() * 1000) |