PHP code example of accelade / ai

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

    

accelade / ai example snippets


use Accelade\AI\Facades\AI;

// Use the default provider
$response = AI::chat([
    ['role' => 'user', 'content' => 'Hello!']
]);

// Use a specific provider
$response = AI::provider('anthropic')->chat([
    ['role' => 'user', 'content' => 'Hello!']
]);

// Stream responses
foreach (AI::stream($messages) as $chunk) {
    echo $chunk;
}
bash
php artisan vendor:publish --tag=accelade-ai-config