Get the current status of a batch job. Args: client: An initialized OpenAI client. batch_id: The batch ID returned by create_batch. Returns: BatchJobInfo with the current status and counts.
(client: OpenAI, batch_id: str)
| 165 | |
| 166 | |
| 167 | def get_batch_status(client: OpenAI, batch_id: str) -> BatchJobInfo: |
| 168 | """Get the current status of a batch job. |
| 169 | |
| 170 | Args: |
| 171 | client: An initialized OpenAI client. |
| 172 | batch_id: The batch ID returned by create_batch. |
| 173 | |
| 174 | Returns: |
| 175 | BatchJobInfo with the current status and counts. |
| 176 | """ |
| 177 | batch = client.batches.retrieve(batch_id) |
| 178 | |
| 179 | return BatchJobInfo( |
| 180 | batch_id=batch.id, |
| 181 | status=batch.status, |
| 182 | total_requests=batch.request_counts.total if batch.request_counts else 0, |
| 183 | completed_requests=batch.request_counts.completed if batch.request_counts else 0, |
| 184 | failed_requests=batch.request_counts.failed if batch.request_counts else 0, |
| 185 | output_file_id=batch.output_file_id, |
| 186 | error_file_id=batch.error_file_id, |
| 187 | ) |
| 188 | |
| 189 | |
| 190 | def poll_batch_until_complete( |
no test coverage detected