PHP code example of php-gemini / generative-ai

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

    

php-gemini / generative-ai example snippets


use Gemini;

echo Gemini::generate("What's the future of AI?");

use PhpGemini\GenerativeAI\GeminiClient;

y' => 'your_api_key',
    'model' => 'gemini-1.5-flash',
]);

echo $gemini->generateContent("Tell me something interesting.");

use PhpGemini\GenerativeAI\GeminiClient;
use PhpGemini\GenerativeAI\Services\OAuth2Service;

our_client_secret',
    'refresh_token' => 'your_refresh_token',
]);

$gemini = new GeminiClient([
    'model' => 'gemini-1.5-flash',
    'oauth2' => $oauth
]);

echo $gemini->generateContent("Tell me something interesting.");

$response = $gemini->generateContentWithImage('path/to/image.jpg', 'What’s in this image?');
bash
composer 
bash
php artisan vendor:publish --provider="PhpGemini\GenerativeAI\Providers\GeminiServiceProvider"