PHP code example of latentkit / laravel

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

    

latentkit / laravel example snippets


use LatentKit\LatentKit;

final class SummarizeReport
{
    public function __construct(private readonly LatentKit $latentKit) {}

    public function __invoke(string $report): string
    {
        $response = $this->latentKit->chat->create([
            ['role' => 'user', 'content' => 'Summarize this report: '.$report],
        ]);

        return $response['content'];
    }
}

use LatentKit\Laravel\Facades\LatentKit;

$context = LatentKit::client()->me->retrieveContext();

use Laravel\Ai\AnonymousAgent;

$response = (new AnonymousAgent(
    instructions: 'Answer clearly and briefly.',
    messages: [],
    tools: [],
))->prompt(
    'Summarize the deployment status.',
    provider: 'latentkit',
);

echo $response->text;

use LatentKit\Laravel\Facades\LatentKit;

$fake = LatentKit::fake([
    ['content' => 'Test summary'],
]);

$result = LatentKit::client()->chat->create([
    ['role' => 'user', 'content' => 'Summarize this'],
]);

$fake->assertChatSent(
    fn (array $request): bool => $request['messages'][0]['content'] === 'Summarize this',
);
bash
composer latentkit-php:0.1.0-beta.3 \
  latentkit/laravel:0.1.0-alpha.1
bash
php artisan vendor:publish --tag=latentkit-config
bash
php artisan latentkit:check