Siteβ―Builder
Editing:
more3.php
writable 0666
<?php // more.php // ββ CONFIGURATION ββ define('COOKIE_NAME','openai_key'); define('COOKIE_TTL', 30 * 24 * 3600); // 30 days define('SECRET', __FILE__); // change for your own salt // β SIMPLE ENCRYPT/DECRYPT β function encrypt_val($v) { $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method)); $ct = openssl_encrypt($v, $method, $key, 0, $iv); return base64_encode("$ct::$iv"); } function decrypt_val($c) { @list($ct,$iv) = explode('::', base64_decode($c), 2); $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); return openssl_decrypt($ct, $method, $key, 0, $iv); } // β HANDLE KEY SAVE/DELETE β $msg = ''; if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['save_key'])) { $raw = trim($_POST['api_key']); $opts = ['http'=>['method'=>'GET','header'=>"Authorization: Bearer $raw\r\n",'timeout'=>10]]; if (@file_get_contents('https://api.openai.com/v1/models', false, stream_context_create($opts))) { setcookie(COOKIE_NAME, encrypt_val($raw), time()+COOKIE_TTL,'/','',isset($_SERVER['HTTPS']),true); $msg = "β Key saved!"; } else { $msg = "β Invalid key."; } } if (isset($_GET['delete_key'])) { setcookie(COOKIE_NAME,'', time()-3600,'/','',isset($_SERVER['HTTPS']),true); header("Location: {$_SERVER['PHP_SELF']}"); exit; } // β PARAMETERS & AUTH β $type = $_GET['type'] ?? 'B'; $scope = $_GET['scope'] ?? 'general'; $word = trim($_GET['word'] ?? ''); $count = intval($_GET['count'] ?? 5); $def = intval($_GET['def'] ?? 1); $count = max(1,min(15,$count)); $def = max(1,min($count,$def)); $cookie = $_COOKIE[COOKIE_NAME] ?? ''; $key = $cookie ? decrypt_val($cookie) : ''; $items = []; // sanitize seed into option name $nm = preg_replace('/[^a-z0-9_]+/','_',strtolower($word)); // β FETCH AI TOKENS (non-numeric) β if ($key && $word && $type !== 'Dnum') { $payload = [ 'model'=>'gpt-3.5-turbo', 'messages'=>[ ['role'=>'system','content'=>"You are a helpful assistant that replies ONLY with a comma-separated list of {$scope}, no extra text."], ['role'=>'user','content'=>"List up to {$count} {$scope} variations for '{$word}'."] ], 'max_tokens'=>60,'temperature'=>0.3,'stop'=>["\n"] ]; $ch = curl_init('https://api.openai.com/v1/chat/completions'); curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>true,CURLOPT_HTTPHEADER=>['Authorization: Bearer '.$key,'Content-Type: application/json'],CURLOPT_POST=>true,CURLOPT_POSTFIELDS=>json_encode($payload),CURLOPT_TIMEOUT=>15]); $resp = curl_exec($ch); curl_close($ch); $data = json_decode($resp,true); $raw = array_filter(array_map('trim',explode(',',$data['choices'][0]['message']['content'] ?? ''))); array_unshift($raw,$word); $items = array_slice(array_unique($raw),0,$count); } ?> <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Promptinator Simple</title> <style> body{font-family:sans-serif;max-width:600px;margin:2rem auto;}label{display:inline-block;width:80px;vertical-align:top;}input,select,button{margin:5px 0;padding:6px;}#tokens{margin:10px 0;} .token{display:inline-block;background:#eee;padding:4px 8px;margin:3px;border-radius:4px;} .token span{margin-left:6px;color:red;cursor:pointer;}pre{background:#f6f6f6;padding:8px;white-space:pre-wrap;}#modal{display:none;position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);align-items:center;justify-content:center;}#modal .inner{background:#fff;padding:20px;border-radius:6px;} </style></head><body> <h2>1) OpenAI API Key</h2> <?php if($msg):?><p><strong><?=htmlspecialchars($msg)?></strong></p><?php endif;?> <?php if(!$key):?> <form method="post"><input type="password" name="api_key" placeholder="sk-..." required><button name="save_key">Save & Validate</button></form> <?php else:?> <p>Key saved. <a href="?delete_key=1">Delete key</a></p><p><em>Using model: <strong>gpt-3.5-turbo</strong></em></p> <?php endif;?> <?php if($key):?> <h2>2) Configure</h2> <form id="cfg"> <label>Type</label> <select id="type" name="type"> <option value="B"<?= $type==='B'?' selected':''?>>Radio</option> <option value="C"<?= $type==='C'?' selected':''?>>Checkbox</option> <option value="Dtxt"<?= $type==='Dtxt'?' selected':''?>>Dropdown Text</option> <option value="Dnum"<?= $type==='Dnum'?' selected':''?>>Dropdown Numeric</option> </select><br> <label>Relation</label> <select id="scope" name="scope"> <option value="general"<?= $scope==='general'?' selected':''?>>General</option> <option value="broad"<?= $scope==='broad'?' selected':''?>>Broad</option> <option value="narrow"<?= $scope==='narrow'?' selected':''?>>Narrow</option> <option value="longtail"<?= $scope==='longtail'?' selected':''?>>Long-tail</option> <option value="shorttail"<?= $scope==='shorttail'?' selected':''?>>Short-tail</option> </select><br> <div id="num-box" style="display:none;"> <label>Max</label><input id="max" type="number" min="1" max="15" value="<?= $count ?>"><br> <label>Default</label><input id="def" type="number" min="1" max="<?= $count ?>" value="<?= $def ?>"><br> <label>Option Name</label><input id="opt" type="text" placeholder="optional"><br> </div> <div id="seed-box"> <label>Seed</label><input id="seed" name="word" value="<?=htmlspecialchars($word)?>"><br> <button id="gen">Generate</button> </div> </form> <h3>3) Tokens</h3> <div id="tokens"></div> <button id="change">Change Default</button> <h3>4) Preview</h3> <pre id="shortcode"></pre> <!-- Default picker modal --> <div id="modal"><div class="inner"> <h3>Select new default</h3> <select id="picker"></select><br> <button id="save">Save</button> <button id="cancel">Cancel</button> </div></div> <script> (() => { const typeEl = document.getElementById('type'), seedBox = document.getElementById('seed-box'), numBox = document.getElementById('num-box'), maxEl = document.getElementById('max'), defEl = document.getElementById('def'), optEl = document.getElementById('opt'), tokensEl= document.getElementById('tokens'), scEl = document.getElementById('shortcode'), changeBtn = document.getElementById('change'), genBtn = document.getElementById('gen'), nm = "<?= $nm ?>", modal = document.getElementById('modal'), picker = document.getElementById('picker'), saveBtn = document.getElementById('save'), cancelBtn = document.getElementById('cancel'); let items = <?= json_encode($items) ?>; function renderTokens() { tokensEl.innerHTML = ''; items.forEach((t,i) => { const span = document.createElement('span'); span.className = 'token'; span.textContent = t; const x = document.createElement('span'); x.textContent = 'Γ'; x.onclick = () => { items.splice(i,1); renderTokens(); updateShortcode(); }; span.appendChild(x); tokensEl.appendChild(span); }); } function updateShortcode() { const t = typeEl.value, ps = items.join('|'), df = items[0] || '', mx = parseInt(maxEl.value,10), dm = parseInt(defEl.value,10), opt = optEl.value || nm; let sc = ''; if (t === 'Dnum') { // numeric dropdown items = []; for (let i=1; i<=mx; i++) items.push(i.toString()); renderTokens(); sc = `[D-${opt}-${mx}~${dm}~]`; } else if (items.length) { sc = `[${t}-${opt}-|${ps}|~${df}~]`; } scEl.textContent = sc; } // Toggle views typeEl.onchange = () => { const isNum = typeEl.value === 'Dnum'; numBox.style.display = isNum ? 'block' : 'none'; seedBox.style.display = isNum ? 'none' : 'block'; updateShortcode(); }; // Listeners [maxEl, defEl, optEl].forEach(el => el.oninput = updateShortcode); // Generate for AI types genBtn.onclick = e => { e.preventDefault(); if (typeEl.value !== 'Dnum') document.getElementById('cfg').submit(); }; // Change default modal changeBtn.onclick = () => { picker.innerHTML = ''; items.forEach(t => { const o = document.createElement('option'); o.value = o.textContent = t; picker.appendChild(o); }); modal.style.display = 'flex'; }; saveBtn.onclick = () => { const v = picker.value, i = items.indexOf(v); if (i>-1) { items.splice(i,1); items.unshift(v); } renderTokens(); updateShortcode(); modal.style.display='none'; }; cancelBtn.onclick = () => modal.style.display = 'none'; // Init renderTokens(); updateShortcode(); typeEl.onchange(); })(); </script> <?php endif; ?> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel