From 8e8cf3872d664f686387f4316eef2c29a15bfaa5 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Fri, 19 Apr 2024 09:38:44 +0100 Subject: [PATCH] Add example for creating a batch --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 67eb858..391c867 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,27 @@ ModerationRequest request = ModerationRequest.newBuilder() Moderation moderation = moderationsClient.createModeration(request); boolean violence = moderation.results().get(0).categories().violence(); ``` +- Create and execute a batch +```java +// Upload JSONL file containing requests for the batch +FilesClient filesClient = openAI.filesClient(); +UploadFileRequest uploadInputFileRequest = UploadFileRequest.newBuilder() + .file(Paths.get("/tmp/batch-requests.jsonl")) + .purpose("batch") + .build(); +File inputFile = filesClient.uploadFile(uploadInputFileRequest); + +BatchClient batchClient = openAI.batchClient(); +CreateBatchRequest request = CreateBatchRequest.newBuilder() + .inputFileId(inputFile.id()) + .endpoint("/v1/chat/completions") + .completionWindow("24h") + .build(); +Batch batch = batchClient.createBatch(request); +// check status of the batch +Batch retrievedBatch = batchClient.retrieveBatch(batch.id()); +System.out.println(retrievedBatch.status()); +``` - Build AI Assistant ```java AssistantsClient assistantsClient = openAI.assistantsClient();