You can check batch operations for completion model, where you need to upload file using file operations and make batch request passing file id got from uploading.
The file format should be of type .jsonl
, create the .jsonl
file with current device configuration file.
Example:
{"custom_id": "task-0", "method": "POST", "url": "/chat/completions", "body": {"model": "REPLACE-WITH-MODEL-DEPLOYMENT-NAME", "messages": [{"role": "system", "content": "<Give prompt to get required output for device 1>"}, {"role": "user", "content": "Your prompt for device config 1"}]}}
{"custom_id": "task-1", "method": "POST", "url": "/chat/completions", "body": {"model": "REPLACE-WITH-MODEL-DEPLOYMENT-NAME", "messages": [{"role": "system", "content": "<Give prompt to get required output for device 2>"}, {"role": "user", "content": "Your prompt for device config 2"}]}}
{"custom_id": "task-2", "method": "POST", "url": "/chat/completions", "body": {"model": "REPLACE-WITH-MODEL-DEPLOYMENT-NAME", "messages": [{"role": "system", "content": "<Give prompt to get required output for device 3>"}, {"role": "user", "content": "Your prompt for device config 1"}]}}
Like this you create for all the device configuration.
Below is the sample
String fileName = "batch_tasks.jsonl";
FileDetails fileDetails = new FileDetails(BinaryData.fromFile(openResourceFile(fileName)), fileName);
OpenAIFile file = client.uploadFile(fileDetails, FilePurpose.BATCH);
String fileId = file.getId();
System.out.println("File uploaded, file ID = " + fileId);
// Create a batch
while (file.getStatus() == FileState.PENDING) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
file = client.getFile(file.getId());
}
Batch batch = client.createBatch(new BatchCreateRequest("/chat/completions", file.getId(), "24h"));
Next get output file content like below.
String outputFileId = batch.getOutputFileId();
byte[] fileContent = client.getFileContent(outputFileId);
System.out.println("File output ID is " + outputFileId);
System.out.println("File content: ");
System.out.println(new String(fileContent));