nhance/app/Controllers/Home.php
2025-08-08 18:05:39 +05:30

60 lines
1.5 KiB
PHP
Executable File

<?php
namespace App\Controllers;
use GeminiAPI\Client;
use GeminiAPI\Resources\ModelName;
use GeminiAPI\Resources\Parts\TextPart;
class Home extends PublicController
{
public function index(): string
{
return view('mail_welcome');
}
public function test()
{
echo base_url();
//echo ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['SERVER_NAME']}".str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
return view('welcome_message');
return view('test');
}
public function testService()
{
return 'from test service';
}
public function addTwoNumbers($payload)
{
//echo $payload['a'] + $payload['b'];
return $payload['a'] + $payload['b'];
}
public function check_Gemini()
{
try {
$apiKey = 'AIzaSyBbx-uotRBqkYhqLpmD60420E_a0G0duP8';
// 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();
}
print_rr($data);
}
}