nhance/app/Libraries/Gemini.php
2025-08-08 18:05:39 +05:30

47 lines
1.4 KiB
PHP

<?php
namespace App\Libraries;
use GeminiAPI\Client;
use GeminiAPI\Resources\ModelName;
use GeminiAPI\Resources\Parts\TextPart;
class Gemini
{
private $client;
private $myLogger;
public function __construct()
{
// $this->myLogger = \Config\Services::mylogger();
// $this->client = new Google_Client();
// $this->client->setAuthConfig(ROOTPATH . 'nhance-app-google-drive.json'); // App credentials
// // putenv('GOOGLE_APPLICATION_CREDENTIALS=' . ROOTPATH . 'nhance-app-google-drive.json');
// $this->client->useApplicationDefaultCredentials();
// $this->client->addScope(Google_Service_Drive::DRIVE); // Full access to Google Drive
}
public function check()
{
try {
// Initialize the Gemini client
$client = new Client($apiKey);
// Send a prompt to the Gemini Pro model
$response = $client->generativeModel(ModelName::GEMINI_PRO)->generateContent(
new TextPart('Write a short, creative story about a knight and a dragon.')
);
// Display the generated text
$data['gemini_response'] = $response->text();
} catch (\Exception $e) {
// Handle any errors that occur during the API call
$data['gemini_response'] = 'An error occurred: ' . $e->getMessage();
}
}
}