| 69 | return outputs |
| 70 | |
| 71 | def collect_errors(self, batch_id): |
| 72 | response = self.client.batches.retrieve(batch_id) |
| 73 | if response.status != "completed": |
| 74 | raise ValueError("The batch is not completed and its status is {}.".format(response.status)) |
| 75 | error_file = response.error_file_id |
| 76 | if error_file == None: |
| 77 | return [] |
| 78 | content = self.client.files.content(error_file) |
| 79 | contents = content.content.splitlines() |
| 80 | outputs = [] |
| 81 | for line in contents: |
| 82 | outputs.append(json.loads(line)) |
| 83 | return outputs |
| 84 | |
| 85 | def batch_run(self, file_id): |
| 86 | response = self.client.batches.create( |