Skip to content

Commit

Permalink
Add example for creating a batch
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Apr 19, 2024
1 parent 5baeb53 commit 8e8cf38
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8e8cf38

Please sign in to comment.