-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge-composer.php
More file actions
38 lines (30 loc) · 1.01 KB
/
Copy pathbridge-composer.php
File metadata and controls
38 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* Bridge Example using Official Gemini PHP Library
* Installation: composer require google-gemini-php/client
* @author Gerits Aurelien
* @license GPLv3
* @link https://www.magix-cms.com https://www.gerits-aurelien.be/
*/
require_once __DIR__ . '/vendor/autoload.php';
header('Content-Type: application/json');
$apiKey = 'VOTRE_CLE_API_ICI';
$client = Gemini::client($apiKey);
// Récupération des données TinyMCE
$input = json_decode(file_get_contents('php://input'), true);
$prompt = $input['prompt'] ?? '';
$context = $input['context'] ?? '';
try {
// Construction du prompt avec consignes HTML
$fullPrompt = "Instructions: $prompt \n Context: $context \n Respond only in semantic HTML.";
$result = $client->geminiFlash()->generateContent($fullPrompt);
echo json_encode([
'status' => 'success',
'html' => $result->text()
]);
} catch (Exception $e) {
echo json_encode([
'status' => 'error',
'message' => 'Erreur Library: ' . $e->getMessage()
]);
}