PHP code example of jkudish / pest-plugin-ai-benchmarks

1. Go to this page and download the library: Download jkudish/pest-plugin-ai-benchmarks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jkudish / pest-plugin-ai-benchmarks example snippets


use Jkudish\PestAiBenchmarks\Configuration;

benchmark('extracts receipts', function (array $case): array {
    return app(ReceiptOcrService::class)
        ->extract($case['file'])
        ->toArray();
})
    ->with('receipt corpus')
    ->configurations([
        'production' => Configuration::production(),
        'gemini-flash' => Configuration::model(
            provider: 'openrouter',
            model: 'google/gemini-3-flash',
        ),
        'new-prompt' => Configuration::settings([
            'receipt_ocr.prompt' => 'receipt-ocr-v2',
        ]),
    ])
    ->evaluate(function (array $output, array $case): void {
        expect($output['merchant_name'])
            ->toBe($case['expected']['merchant_name'])
            ->and($output['total_amount'])
            ->toBe($case['expected']['total_amount']);
    })
    ->dependsOn([
        ReceiptOcrService::class,
        'config/receipt-ocr.php',
    ])
    ->repeat(3);

beforeEach(function (): void {
    benchmarks()->configure(
        provider: 'receipt_ocr.provider',
        model: 'receipt_ocr.model',
        options: 'receipt_ocr.options',
        settings: ['receipt_ocr.prompt'],
    );
});

->evaluate(function (string $output): void {
    expect($output)->toPassBenchmarkScorer(
        scorer: new ReceiptAccuracyScorer,
        threshold: 0.9,
    );
})

->evaluate(function (string $output): void {
    expect($output)->toPassBenchmarkScorers([
        [new LeakScorer, 1.0],
        [new ReceiptAccuracyScorer, 0.9],
    ]);
})

use App\Ai\Agents\ReceiptOcrAgent;
use Jkudish\PestAiBenchmarks\LaravelAi\BenchmarkAgentMiddleware;
use Laravel\Ai\Attributes\Strict;
use Laravel\Ai\Attributes\Timeout;
use Laravel\Ai\Contracts\HasMiddleware;

#[Strict]
#[Timeout(60)]
final class BenchmarkReceiptOcrAgent extends ReceiptOcrAgent implements HasMiddleware
{
    public function middleware(): array
    {
        return [new BenchmarkAgentMiddleware];
    }
}

use Jkudish\PestAiBenchmarks\LaravelAi\InstrumentedAgent;

InstrumentedAgent::assertFaithful(BenchmarkReceiptOcrAgent::class);

benchmarks()->promote(
    run: '20260809T120000Z-abc123',
    baseline: 'production',
);

->failWhen([
    'pass_rate_drop' => 0.05,
    'median_latency_increase' => 0.20,
    'average_cost_increase' => 0.15,
])