1. Go to this page and download the library: Download aysnc/llm-eval 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/ */
// evals/simple.php
use Aysnc\AI\LlmEval\Dataset\Dataset;
use Aysnc\AI\LlmEval\LlmEval;
$dataset = Dataset::fromArray([
['prompt' => 'What is 2+2? Reply with just the number.', 'expected' => '4'],
['prompt' => 'What is the capital of France? Reply with just the city name.', 'expected' => 'Paris'],
['prompt' => 'Is the sky blue? Reply with just yes or no.', 'expected' => 'yes'],
]);
return LlmEval::create('quick-start')
->dataset($dataset)
->assertions(function ($expect, $testCase): void {
$expect->contains($testCase->getExpected(), caseSensitive: false);
});
$dataset = Dataset::fromArray([
[
'turns' => [
['prompt' => 'What is the weather in Paris?', 'expected' => '22'],
['prompt' => 'Now check Tokyo', 'expected' => '18'],
['prompt' => 'Which city was warmer?', 'expected' => 'Paris'],
],
],
]);
return LlmEval::createConversation('multi-turn')
->withTools($tools)
->executor($executor)
->dataset($dataset)
->assertions(function ($expect, $testCase): void {
$expect->contains($testCase->getExpected());
if ($testCase->getTurn() <= 2) {
$expect->usedTool('get_weather');
}
});
// evals/quality-check.php
use Aysnc\AI\LlmEval\Providers\AnthropicProvider;
$judge = new AnthropicProvider(getenv('ANTHROPIC_API_KEY'));
return LlmEval::create('quality-check')
->dataset($dataset)
->assertions(function ($expect) use ($judge): void {
$expect->judgedBy(
judge: $judge,
criteria: 'Is this response helpful, accurate, and concise?',
threshold: 0.8,
);
});
return LlmEval::createConversation('multi-turn')
->withTools($tools)
->executor($executor)
->dataset($dataset)
->assertions(function ($expect, $testCase): void {
$expect->contains($testCase->getExpected());
})
->judge($judge, 'Did the model correctly identify the warmer city based on the earlier temperatures?');
$provider = new AnthropicProvider(
apiKey: getenv('ANTHROPIC_API_KEY'),
);
use Aysnc\AI\LlmEval\Providers\BedrockProvider;
// Explicit credentials
$provider = new BedrockProvider(
region: 'us-east-1',
accessKeyId: 'AKIA...',
secretAccessKey: 'secret...',
);
// Or default credential chain (env vars, ~/.aws/credentials, IAM role)
$provider = new BedrockProvider(region: 'us-east-1');