Skip to content

Commit 17fb13a

Browse files
Merge pull request #865 from mrbullwinkle/mrb_10_16_2024_batch_fix
[Azure OpenAI] Batch updates
2 parents e6def1f + 9c0dff3 commit 17fb13a

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

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

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ The following models support global batch:
6161
| `gpt-35-turbo` | 1106 | text |
6262
| `gpt-35-turbo` | 0613 | text |
6363

64-
65-
6664
Refer to the [models page](../concepts/models.md) for the most up-to-date information on regions/models where global batch is currently supported.
6765

6866
### API support
@@ -166,7 +164,63 @@ The `2024-10-01-preview` REST API adds two new response headers:
166164
* `deployment-enqueued-tokens` - A approximate token count for your jsonl file calculated immediately after the batch request is submitted. This value represents an estimate based on the number of characters and is not the true token count.
167165
* `deployment-maximum-enqueued-tokens` The total available enqueued tokens available for this global batch model deployment.
168166

169-
These response headers are only available when making a POST request to begin batch processing of a file with the REST API. The language specific client libraries do not currently return these new response headers.
167+
These response headers are only available when making a POST request to begin batch processing of a file with the REST API. The language specific client libraries do not currently return these new response headers. To return all response headers you can add `-i` to the standard REST request.
168+
169+
```http
170+
curl -i -X POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/batches?api-version=2024-10-01-preview \
171+
-H "api-key: $AZURE_OPENAI_API_KEY" \
172+
-H "Content-Type: application/json" \
173+
-d '{
174+
"input_file_id": "file-abc123",
175+
"endpoint": "/chat/completions",
176+
"completion_window": "24h"
177+
}'
178+
```
179+
180+
```output
181+
HTTP/1.1 200 OK
182+
Content-Length: 619
183+
Content-Type: application/json; charset=utf-8
184+
Vary: Accept-Encoding
185+
Request-Context: appId=
186+
x-ms-response-type: standard
187+
deployment-enqueued-tokens: 139
188+
deployment-maximum-enqueued-tokens: 740000
189+
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
190+
X-Content-Type-Options: nosniff
191+
x-aml-cluster: vienna-swedencentral-01
192+
x-request-time: 2.125
193+
apim-request-id: c8bf4351-c6f5-4bfe-9a79-ef3720eca8af
194+
x-ms-region: Sweden Central
195+
Date: Thu, 17 Oct 2024 01:45:45 GMT
196+
197+
{
198+
"cancelled_at": null,
199+
"cancelling_at": null,
200+
"completed_at": null,
201+
"completion_window": "24h",
202+
"created_at": 1729129545,
203+
"error_file_id": null,
204+
"expired_at": null,
205+
"expires_at": 1729215945,
206+
"failed_at": null,
207+
"finalizing_at": null,
208+
"id": "batch_c8dd49a7-c808-4575-9957-b188cd0dd642",
209+
"in_progress_at": null,
210+
"input_file_id": "file-f89384af0082485da43cb26b49dc25ce",
211+
"errors": null,
212+
"metadata": null,
213+
"object": "batch",
214+
"output_file_id": null,
215+
"request_counts": {
216+
"total": 0,
217+
"completed": 0,
218+
"failed": 0
219+
},
220+
"status": "validating",
221+
"endpoint": "/chat/completions"
222+
}
223+
```
170224

171225
### What happens if the API doesn't complete my request within the 24 hour time frame?
172226

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ For this article we'll create a file named `test.jsonl` and will copy the conten
7474

7575
Once your input file is prepared, you first need to upload the file to then be able to kick off a batch job. File upload can be done both programmatically or via the Studio. This example uses environment variables in place of the key and endpoint values. If you're unfamiliar with using environment variables with Python refer to one of our [quickstarts](../../chatgpt-quickstart.md) where the process of setting up the environment variables in explained step-by-step.
7676

77-
[!INCLUDE [Azure key vault](~/reusable-content/ce-skilling/azure/includes/ai-services/security/azure-key-vault.md)]
78-
7977
# [Python (Microsoft Entra ID)](#tab/python-secure)
8078

8179
```python
@@ -105,6 +103,8 @@ file_id = file.id
105103

106104
# [Python (API Key)](#tab/python-key)
107105

106+
[!INCLUDE [Azure key vault](~/reusable-content/ce-skilling/azure/includes/ai-services/security/azure-key-vault.md)]
107+
108108
```python
109109
import os
110110
from openai import AzureOpenAI
@@ -144,7 +144,7 @@ file_id = file.id
144144

145145
## Create batch job
146146

147-
Once your file has uploaded successfully by reaching a status of `processed` you can submit the file for batch processing.
147+
Once your file has uploaded successfully you can submit the file for batch processing.
148148

149149
```python
150150
# Submit a batch job with the file
@@ -405,7 +405,7 @@ client.batches.list()
405405

406406
Use the REST API to list all batch jobs with additional sorting/filtering options.
407407

408-
In the examples below we are providing the `generate_time_filter` function to make constructing the filter easier. If you don't wish to use this function the format of the filter string would look like `created_at gt 1728773533 and created_at lt 1729032733 and status eq 'Completed'`.
408+
In the examples below we are providing the `generate_time_filter` function to make constructing the filter easier. If you don't wish to use this function the format of the filter string would look like `created_at gt 1728860560 and status eq 'Completed'`.
409409

410410
# [Python (Microsoft Entra ID)](#tab/python-secure)
411411

@@ -441,9 +441,8 @@ def generate_time_filter(time_range, status=None):
441441
raise ValueError("Invalid time range format. Use 'past X day(s)' or 'past X hour(s)'")
442442

443443
start_timestamp = int(start_time.timestamp())
444-
end_timestamp = int(now.timestamp())
445444

446-
filter_string = f"created_at gt {start_timestamp} and created_at lt {end_timestamp}"
445+
filter_string = f"created_at gt {start_timestamp}"
447446

448447
if status:
449448
filter_string += f" and status eq '{status}'"
@@ -504,9 +503,8 @@ def generate_time_filter(time_range, status=None):
504503
raise ValueError("Invalid time range format. Use 'past X day(s)' or 'past X hour(s)'")
505504

506505
start_timestamp = int(start_time.timestamp())
507-
end_timestamp = int(now.timestamp())
508506

509-
filter_string = f"created_at gt {start_timestamp} and created_at lt {end_timestamp}"
507+
filter_string = f"created_at gt {start_timestamp}"
510508

511509
if status:
512510
filter_string += f" and status eq '{status}'"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files/{file-id}?api-vers
118118

119119
## Create batch job
120120

121-
Once your file has uploaded successfully by reaching a status of `processed` you can submit the file for batch processing.
121+
Once your file has uploaded successfully you can submit the file for batch processing.
122122

123123
```http
124124
curl -X POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/batches?api-version=2024-10-01-preview \

0 commit comments

Comments
 (0)