B09_BatchInference
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
<?php
require 'examples/boot.php';
require __DIR__.'/../Support/DemoBatch.php';
use Cognesy\Polyglot\BatchInference\Data\BatchReference;
use Cognesy\Polyglot\BatchInference\Enums\BatchStatus;
use Examples\BatchInference\Support\DemoBatch;
$batches = DemoBatch::client();
$submitted = $batches->submit(DemoBatch::items());
$reference = BatchReference::fromArray($submitted->reference()->toArray());
$observed = $batches->retrieve($reference);
$outcomes = iterator_to_array($batches->results($reference)->items());
if ($submitted->status() !== BatchStatus::Pending
|| $observed->status() !== BatchStatus::Completed
|| $outcomes[0]->key() !== 'row-1'
|| !$outcomes[0]->result()->isSuccess()
|| $outcomes[1]->key() !== 'row-2'
|| !$outcomes[1]->result()->isFailure()) {
throw new RuntimeException('Unexpected batch lifecycle outcome.');
}
echo "Batch {$reference->id()->toString()}: 1 success, 1 item failure\n";
?>