PHP code example of adeel696 / ai-wrapper

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

    

adeel696 / ai-wrapper example snippets

bash
php artisan vendor:publish --tag=config
bash
return [

    'default_provider' => 'openai',
    'default_model' => 'gpt-3.5-turbo',

    'providers' => [
        'openai' => ['api_key' => env('OPENAI_API_KEY')],
        'anthropic' => ['api_key' => env('ANTHROPIC_API_KEY')],
        'google' => ['api_key' => env('GOOGLE_AI_API_KEY')],
    ],

    'models' => [
        'openai' => ['default' => 'gpt-3.5-turbo'],
        'claude' => ['default' => 'claude-3-opus-20240229'],
        'gemini' => ['default' => 'gemini-pro'],
    ],
];
bash
$response = $ai->chat("Tell me about Laravel.");
echo $response;
bash
$text = "Laravel is a PHP framework designed for web artisans...";
echo $ai->summarize($text);
bash
echo $ai->translate("How are you?", "es");
bash
$vector = $ai->embed("What is AI?");
print_r($vector);
bash
$response = $ai->transcribeAudio(storage_path('audio/voice.mp3'));
echo $response;
bash
$ai->stream("Tell me a joke.", function ($chunk) {
    echo $chunk;
});