| 137 | return results |
| 138 | |
| 139 | def save_single(self, index: int, input: T_INPUT, output: T_OUTPUT, session: Session=None): |
| 140 | save_obj = { |
| 141 | "index": index, |
| 142 | "input": serialize(input), |
| 143 | "output": serialize(output), |
| 144 | "history": session.history if session else None, |
| 145 | "exception_raised": session.exception_raised if session else None |
| 146 | } |
| 147 | if not os.path.exists(self.get_output_dir()): |
| 148 | try: os.makedirs(self.get_output_dir()) |
| 149 | except: pass |
| 150 | with open(os.path.join(self.get_output_dir(), "generation.jsonl"), "a", encoding="utf-8") as f: |
| 151 | f.write(json.dumps(save_obj, ensure_ascii=False) + "\n") |
| 152 | |
| 153 | def save_runs_all(self, inputs: List[T_INPUT], outputs: List[T_OUTPUT], targets: List[T_TARGET], metrics: Dict[str, Any] = None): |
| 154 | if not os.path.exists(self.get_output_dir()): |