-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gemini_api.php
45 lines (37 loc) · 1.15 KB
/
test_gemini_api.php
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
39
40
41
42
43
44
45
<?php
// Clé API Gemini fournie par l'utilisateur
$apiKey = 'AIzaSyAHGWEZe3xMZLRbtOUtufclqYmn_mgOlls';
// URL de l'API pour générer du contenu avec Gemini
$url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=' . $apiKey;
// Données à envoyer
$data = [
'contents' => [
[
'parts' => [
[
'text' => 'Explain how AI works in one sentence'
]
]
]
]
];
// Initialiser cURL
$ch = curl_init($url);
// Configurer la requête
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Exécuter la requête
$response = curl_exec($ch);
// Vérifier les erreurs
if (curl_errno($ch)) {
echo 'Erreur cURL: ' . curl_error($ch) . "\n";
} else {
// Afficher la réponse
echo "Réponse de l'API Gemini:\n";
$responseData = json_decode($response, true);
echo json_encode($responseData, JSON_PRETTY_PRINT);
}
// Fermer la session cURL
curl_close($ch);