Skip to content

Commit 576524d

Browse files
Merge pull request #111 from mrbullwinkle/mrb_09_03_2024_batch
[Azure OpenAI] Batch Updates
2 parents 6f191ad + 4dcb75a commit 576524d

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

articles/ai-services/openai/how-to/batch.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ manager: nitinme
66
ms.service: azure-ai-openai
77
ms.custom:
88
ms.topic: how-to
9-
ms.date: 08/30/2024
9+
ms.date: 09/04/2024
1010
author: mrbullwinkle
1111
ms.author: mbullwin
1212
recommendations: false
@@ -169,37 +169,39 @@ When a job failure occurs, you'll find details about the failure in the `errors`
169169
```json
170170
"value": [
171171
{
172-
"cancelled_at": null,
173-
"cancelling_at": null,
174-
"completed_at": "2024-06-27T06:50:01.6603753+00:00",
175-
"completion_window": null,
176-
"created_at": "2024-06-27T06:37:07.3746615+00:00",
177-
"error_file_id": "file-f13a58f6-57c7-44d6-8ceb-b89682588072",
178-
"expired_at": null,
179-
"expires_at": "2024-06-28T06:37:07.3163459+00:00",
180-
"failed_at": null,
181-
"finalizing_at": "2024-06-27T06:49:59.1994732+00:00",
182-
"id": "batch_50fa47a0-ef19-43e5-9577-a4679b92faff",
183-
"in_progress_at": "2024-06-27T06:39:57.455977+00:00",
184-
"input_file_id": "file-42147e78ea42488682f4fd1d73028e72",
185-
"errors": {
172+
"id": "batch_80f5ad38-e05b-49bf-b2d6-a799db8466da",
173+
"completion_window": "24h",
174+
"created_at": 1725419394,
175+
"endpoint": "/chat/completions",
176+
"input_file_id": "file-c2d9a7881c8a466285e6f76f6321a681",
177+
"object": "batch",
178+
"status": "failed",
179+
"cancelled_at": null,
180+
"cancelling_at": null,
181+
"completed_at": 1725419955,
182+
"error_file_id": "file-3b0f9beb-11ce-4796-bc31-d54e675f28fb",
183+
"errors": {
186184
"object": “list”,
187185
"data": [
188186
{
189187
“code”: “empty_file”,
190188
“message”: “The input file is empty. Please ensure that the batch contains at least one request.”
191189
}
192190
]
193-
},
194-
"metadata": null,
195-
"object": "batch",
196-
"output_file_id": "file-22d970b7-376e-4223-a307-5bb081ea24d7",
191+
},
192+
"expired_at": null,
193+
"expires_at": 1725505794,
194+
"failed_at": null,
195+
"finalizing_at": 1725419710,
196+
"in_progress_at": 1725419572,
197+
"metadata": null,
198+
"output_file_id": "file-ef12af98-dbbc-4d27-8309-2df57feed572",
199+
197200
"request_counts": {
198201
"total": 10,
199202
"completed": null,
200203
"failed": null
201204
},
202-
"status": "Failed"
203205
}
204206
```
205207

articles/ai-services/openai/includes/batch/batch-python.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ while status not in ("completed", "failed", "canceled"):
198198
batch_response = client.batches.retrieve(batch_id)
199199
status = batch_response.status
200200
print(f"{datetime.datetime.now()} Batch Id: {batch_id}, Status: {status}")
201+
202+
if batch_response.status == "failed":
203+
for error in batch_response.errors.data:
204+
print(f"Error code {error.code} Message {error.message}")
201205
```
202206

203207
**Output:**
@@ -271,13 +275,19 @@ Observe that there's both `error_file_id` and a separate `output_file_id`. Use t
271275
```python
272276
import json
273277

274-
file_response = client.files.content(batch_response.output_file_id)
275-
raw_responses = file_response.text.strip().split('\n')
278+
output_file_id = batch_response.output_file_id
279+
280+
if not output_file_id:
281+
output_file_id = batch_response.error_file_id
282+
283+
if output_file_id:
284+
file_response = client.files.content(output_file_id)
285+
raw_responses = file_response.text.strip().split('\n')
276286

277-
for raw_response in raw_responses:
278-
json_response = json.loads(raw_response)
279-
formatted_json = json.dumps(json_response, indent=2)
280-
print(formatted_json)
287+
for raw_response in raw_responses:
288+
json_response = json.loads(raw_response)
289+
formatted_json = json.dumps(json_response, indent=2)
290+
print(formatted_json)
281291
```
282292

283293
**Output:**

0 commit comments

Comments
 (0)