Skip to content

Commit d66b503

Browse files
committed
update
1 parent 0deb6d6 commit d66b503

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

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

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,98 @@ Observe that there's both `error_file_id` and a separate `output_file_id`. Use t
265265
## Retrieve batch job output file
266266

267267
```python
268+
import json
269+
268270
response =client.files.content(batch_response.output_file_id)
271+
raw_responses = file_response.text.strip().split('\n')
272+
273+
for raw_response in raw_responses:
274+
json_response = json.loads(raw_response)
275+
formatted_json = json.dumps(json_response, indent=2)
276+
print(formatted_json)
277+
```
278+
279+
**Output:**
269280

270-
print(response.text)
281+
For brevity, we are only including a single chat completion response of output. If you follow the steps in this article you should have three responses similar to the one below:
282+
283+
```json
284+
{
285+
"custom_id": "task-0",
286+
"response": {
287+
"body": {
288+
"choices": [
289+
{
290+
"content_filter_results": {
291+
"hate": {
292+
"filtered": false,
293+
"severity": "safe"
294+
},
295+
"self_harm": {
296+
"filtered": false,
297+
"severity": "safe"
298+
},
299+
"sexual": {
300+
"filtered": false,
301+
"severity": "safe"
302+
},
303+
"violence": {
304+
"filtered": false,
305+
"severity": "safe"
306+
}
307+
},
308+
"finish_reason": "stop",
309+
"index": 0,
310+
"logprobs": null,
311+
"message": {
312+
"content": "Microsoft was founded on April 4, 1975, by Bill Gates and Paul Allen in Albuquerque, New Mexico.",
313+
"role": "assistant"
314+
}
315+
}
316+
],
317+
"created": 1722477079,
318+
"id": "chatcmpl-9rFGJ9dh08Tw9WRKqaEHwrkqRa4DJ",
319+
"model": "gpt-4o-2024-05-13",
320+
"object": "chat.completion",
321+
"prompt_filter_results": [
322+
{
323+
"prompt_index": 0,
324+
"content_filter_results": {
325+
"hate": {
326+
"filtered": false,
327+
"severity": "safe"
328+
},
329+
"jailbreak": {
330+
"filtered": false,
331+
"detected": false
332+
},
333+
"self_harm": {
334+
"filtered": false,
335+
"severity": "safe"
336+
},
337+
"sexual": {
338+
"filtered": false,
339+
"severity": "safe"
340+
},
341+
"violence": {
342+
"filtered": false,
343+
"severity": "safe"
344+
}
345+
}
346+
}
347+
],
348+
"system_fingerprint": "fp_a9bfe9d51d",
349+
"usage": {
350+
"completion_tokens": 24,
351+
"prompt_tokens": 27,
352+
"total_tokens": 51
353+
}
354+
},
355+
"request_id": "660b7424-b648-4b67-addc-862ba067d442",
356+
"status_code": 200
357+
},
358+
"error": null
359+
}
271360
```
272361

273362
### Additional batch commands

0 commit comments

Comments
 (0)