apiKey = $apiKey; $this->model = $model; } function headers() { if ($_POST["gemini"] && !isset($_POST["query"])) { $prompt = "I have a " . Adminer\get_driver(Adminer\DRIVER) . " database with this structure:\n\n"; foreach (Adminer\tables_list() as $table => $type) { $prompt .= Adminer\create_sql($table, false, "CREATE") . ";\n\n"; } $prompt .= "Prefer returning more columns including primary key.\n\n"; $prompt .= "Give me this SQL query and nothing else:\n\n$_POST[gemini]\n\n"; //~ echo $prompt; exit; $context = stream_context_create(array("http" => array( "method" => "POST", "header" => array("User-Agent: AdminerSqlGemini", "Content-Type: application/json"), "content" => '{"contents": [{"parts":[{"text": ' . json_encode($prompt) . '}]}]}', ))); $response = json_decode(file_get_contents("https://generativelanguage.googleapis.com/v1beta/models/$this->model:generateContent?key=$this->apiKey", false, $context)); $text = $response->candidates[0]->content->parts[0]->text; $in_code = false; foreach (preg_split('~(^|\n)```(sql)?(\n|$)~', $text) as $part) { $part = trim($part); if ($part) { echo ($in_code ? $part : "/*\n$part\n*/") . "\n\n"; } $in_code = !$in_code; } exit; } } function sqlPrintAfter() { echo "
\n"; ?>