apiKey = $apiKey; $this->model = $model; } function headers() { if ($_POST["gemini"] && !isset($_POST["query"])) { $prompt = "I have a database with this structure:\n\n"; foreach (Adminer\tables_list() as $table => $type) { $prompt .= Adminer\create_sql($table, false, "CREATE") . ";\n\n"; } $prompt .= "Give me this SQL query and nothing else:\n\n$_POST[gemini]"; //~ 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; echo preg_replace('~```sql\n(.*\n)```~s', '\1', $text) . "\n"; exit; } } function sqlPrintAfter() { echo "
\n"; echo "
" . Adminer\script("qsl('input').onclick = function () { ajax( '', req => { qs('textarea.sqlarea').value = req.responseText; const sqlarea = qs('pre.sqlarea'); sqlarea.textContent = req.responseText; sqlarea.oninput(); // syntax highlighting }, 'gemini=' + encodeURIComponent(this.form['gemini'].value) ); }"); } }