[ [ "parts" => [ ["text" => $prompt] ] ] ] ]; // JSON formatga o'tkazamiz $jsonData = json_encode($data); // 5. cURL orqali so'rov yuborishni sozlash $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); // So'rovni bajarish va javobni olish $response = curl_exec($ch); // Xatoliklarni tekshirish if (curl_errno($ch)) { echo 'cURL Xatolik yuz berdi: ' . curl_error($ch); exit; } curl_close($ch); // 6. Kelgan javobni (JSON) massivga o'girish $result = json_decode($response, true); // 7. Natijani ekranga chiqarish if (isset($result['candidates'][0]['content']['parts'][0]['text'])) { $aiResponse = $result['candidates'][0]['content']['parts'][0]['text']; echo "

Sizning so'rovingiz:

"; echo "

" . htmlspecialchars($prompt) . "

"; echo "
"; echo "

Gemini javobi:

"; // Markdown formatidagi javobni chiroyli ko'rsatish uchun nl2br ishlatamiz echo nl2br(htmlspecialchars($aiResponse)); } else { echo "Xatolik yuz berdi yoki API kalit noto'g'ri. To'liq javob:
"; echo "
" . print_r($result, true) . "
"; }