PHP code example of mosaiqo / proofread

1. Go to this page and download the library: Download mosaiqo/proofread 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/ */

    

mosaiqo / proofread example snippets


namespace App\Agents;

use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;
use Stringable;

class SentimentAgent implements Agent
{
    use Promptable;

    public function instructions(): Stringable|string
    {
        return <<<'PROMPT'
            You are a sentiment classifier.
            Classify the user message as exactly one of: positive, negative, neutral.
            Respond with a single lowercase word. No punctuation, no explanation.
            PROMPT;
    }
}

use App\Agents\SentimentAgent;
use Mosaiqo\Proofread\Assertions\CostLimit;
use Mosaiqo\Proofread\Assertions\RegexAssertion;
use Mosaiqo\Proofread\Assertions\Rubric;
use Mosaiqo\Proofread\Support\Dataset;

it('classifies sentiment reliably and cheaply', function (): void {
    $dataset = Dataset::make('sentiment', [
        ['input' => 'I love this product!', 'expected' => 'positive'],
        ['input' => 'This is terrible.', 'expected' => 'negative'],
        ['input' => 'It works as described.', 'expected' => 'neutral'],
    ]);

    expect(SentimentAgent::class)->toPassEval($dataset, [
        RegexAssertion::make('/^(positive|negative|neutral)$/'),
        Rubric::make('response is a single lowercase sentiment label'),
        CostLimit::under(0.01),
    ]);
});

namespace App\Evals;

use App\Agents\SentimentAgent;
use Mosaiqo\Proofread\Assertions\RegexAssertion;
use Mosaiqo\Proofread\Suite\EvalSuite;
use Mosaiqo\Proofread\Support\Dataset;

final class SentimentSuite extends EvalSuite
{
    public function dataset(): Dataset
    {
        return Dataset::make('sentiment', [
            ['input' => 'I love this product!', 'expected' => 'positive'],
            ['input' => 'This is terrible.', 'expected' => 'negative'],
        ]);
    }

    public function subject(): mixed
    {
        return SentimentAgent::class;
    }

    public function assertions(): array
    {
        return [
            RegexAssertion::make('/^(positive|negative|neutral)$/'),
        ];
    }
}

abstract public function dataset(): Dataset;
abstract public function subject(): mixed;
abstract public function assertions(): array;

$run = expect($agent)->toPassEval($dataset, $assertions)->value;

expect($run->total_cost_usd)->toBeLessThan(0.05);
expect($run->failures())->toBeEmpty();



use App\Agents\SentimentAgent;
use Mosaiqo\Proofread\Assertions\RegexAssertion;
use Mosaiqo\Proofread\Shadow\ShadowAssertionsRegistry;

public function boot(ShadowAssertionsRegistry $registry): void
{
    $registry->register(SentimentAgent::class, [
        RegexAssertion::make('/^(positive|negative|neutral)$/'),
    ]);
}

'shadow' => [
    'enabled' => true,
    'sample_rate' => 0.1,
    'queue' => 'default',
    'alerts' => [
        'enabled' => true,
        'pass_rate_threshold' => 0.85,
        'window' => '1h',
        'channels' => ['mail', 'slack'],
    ],
],

final class SentimentMatrixSuite extends MultiSubjectEvalSuite
{
    public function name(): string
    {
        return 'sentiment-matrix';
    }

    public function dataset(): Dataset
    {
        return Dataset::make('sentiment', [...]);
    }

    public function subjects(): array
    {
        return [
            'haiku'  => SentimentAgentHaiku::class,
            'sonnet' => SentimentAgentSonnet::class,
            'opus'   => SentimentAgentOpus::class,
        ];
    }

    public function assertions(): array
    {
        return [Rubric::make('Must classify correctly.')->minScore(0.8)];
    }
}

use Illuminate\Support\Facades\Gate;

public function boot(): void
{
    Gate::define('viewEvals', fn ($user) => $user?->isAdmin() === true);
}

'pricing' => [
    'models' => [
        'claude-sonnet-4-6' => [
            'input_per_1m' => 3.00,
            'output_per_1m' => 15.00,
            'cache_read_per_1m' => 0.30,
            'cache_write_per_1m' => 3.75,
        ],
        // ...
    ],
],

use Laravel\Mcp\Server;
use Mosaiqo\Proofread\Mcp\McpIntegration;

class ProofreadMcpServer extends Server
{
    protected array $tools = McpIntegration::tools();
}

'mcp' => [
    'suites' => [
        \App\Evals\SentimentSuite::class,
    ],
],

use Mosaiqo\Proofread\Cli\Subjects\ClaudeCodeCliSubject;
use Mosaiqo\Proofread\Runner\EvalRunner;

$subject = ClaudeCodeCliSubject::make()
    ->withModel('claude-sonnet-4-6')
    ->withTimeout(60);

$run = (new EvalRunner)->run($subject, $dataset, $assertions);

use Mosaiqo\Proofread\Cli\CliResponse;
use Mosaiqo\Proofread\Cli\CliSubject;

final class MyCliSubject extends CliSubject
{
    public function binary(): string
    {
        return 'mycli';
    }

    public function args(string $prompt): array
    {
        return ['--prompt', $prompt, '--json'];
    }

    public function parseOutput(string $stdout, string $stderr): CliResponse
    {
        $decoded = json_decode($stdout, true);

        return new CliResponse(
            output: $decoded['response'] ?? '',
            metadata: [
                'tokens_in' => $decoded['tokens']['in'] ?? null,
                'tokens_out' => $decoded['tokens']['out'] ?? null,
                'model' => $decoded['model'] ?? null,
            ],
        );
    }
}
bash
php artisan vendor:publish --tag=proofread-config
php artisan vendor:publish --tag=proofread-migrations
php artisan migrate
bash
php artisan evals:run "App\\Evals\\SentimentSuite"
bash
php artisan evals:providers App\\Evals\\SentimentMatrixSuite --persist --provider-concurrency=3
bash
php artisan vendor:publish --tag=proofread-workflows
bash
php artisan evals:compare "$BASE_RUN_ID" "$HEAD_RUN_ID" \
    --format=markdown \
    --output=storage/evals/pr-comment.md
bash
php artisan vendor:publish --tag=proofread-pulse
bash
php artisan vendor:publish --tag=proofread-boost-guidelines
bash
php artisan vendor:publish --tag=proofread-config