PHP code example of bdowson / simple-gemini

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

    

bdowson / simple-gemini example snippets




impleGemini\SimpleGemini;
use SimpleGemini\Exceptions\SimpleGeminiException;

try {
    $googleCredentialsPath = '/path/to/credentials.json';
    $project  = 'your-project-id';
    $location = 'asia-southeast1';
    $model    = 'gemini-1.5-flash-002';

    // Optional: Specify generation configuration and safety settings
    $generationConfig = [
        'maxOutputTokens' => 8000,
        // Additional configuration parameters (e.g., temperature, topP, etc.) can be added here.
    ];
    $safetySettings = [
        // Optional safety settings can be specified here.
    ];

    // Instantiate the SimpleGemini client
    $simpleGemini = new SimpleGemini(
        $googleCredentialsPath,
        $project,
        $location,
        $model,
        $generationConfig,
        $safetySettings
    );

    // Send a prompt and get the generated response
    $prompt   = "Write me a poem about software development";
    $response = $simpleGemini->prompt($prompt);

    echo "AI Response:\n" . $response . "\n";
} catch (SimpleGeminiException $e) {
    echo "An error occurred: " . $e->getMessage() . "\n";
}

  $generationConfig = [
      'maxOutputTokens' => 8000,
      'temperature' => 1,
      // You can also