Site Builder
Editing:
index33.php
writable 0666
<?php /* /openai/index.php – Quick tester + docs */ require_once __DIR__.'/init.php'; ai_handle_key_post(); $answer=''; if (ai_has_key() && $_SERVER['REQUEST_METHOD']==='POST') { $prompt = trim($_POST['prompt']??''); if ($prompt) { $answer = ai_chat($prompt, [ 'model' => $_POST['model'] ?? 'gpt-4o-mini', 'temperature' => 0.7, 'max_tokens' => 300 ]); } } ?> <!doctype html><html lang="en"><head> <meta charset="utf-8"><meta name=viewport content="width=device-width,initial-scale=1"> <title>OpenAI Connector • BestDealOn</title> <style> :root{--bg:#f1f4fb;--card:#fff;--brand:#004cff;--dark:#121720;--radius:26px; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif} body{margin:0;min-height:100vh;background:var(--bg);display:flex;flex-direction:column;color:#111} .breadcrumb{background:#ececec;font-weight:600;padding:.7rem 1.2rem} .breadcrumb a{color:var(--brand);text-decoration:none} main{max-width:900px;margin:2rem auto;padding:0 1.2rem;flex:1;width:100%} .card{background:var(--card);padding:2rem;border-radius:var(--radius);box-shadow:0 6px 30px rgba(0,0,0,.08);margin-top:2rem} .card h2{margin-top:0} label{font-weight:600;font-size:.95rem;display:block;margin-bottom:.6rem} textarea{width:100%;min-height:120px;padding:.8rem;border:1px solid #ccd4e8;border-radius:10px;font-size:1rem} button{background:var(--brand);color:#fff;border:none;border-radius:10px;padding:.7rem 1.6rem;font-size:1rem;font-weight:600;cursor:pointer;margin-top:1rem} pre{white-space:pre-wrap;background:#fff;border:1px solid #dfe3ef;border-radius:10px;padding:1rem;margin-top:1.2rem;font-size:.9rem} table{border-collapse:collapse;width:100%;margin-top:1rem;font-size:.95rem} th,td{padding:.5rem .7rem;border:1px solid #ccd4e8;text-align:left} #spin{display:none;margin-top:1rem;gap:.5ch;align-items:center} #spin.show{display:flex}@keyframes rot{to{transform:rotate(360deg)}} #spin svg{width:18px;height:18px;animation:rot 1s linear infinite} a.inline{color:#5af287;text-decoration:none} </style></head><body> <nav class="breadcrumb"> <a href="/members/dashboard.php">Dashboard</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » OpenAI Test <a href="/<?= $_SESSION['slug']??''?>/" style="float:right">View Site</a> </nav> <?php ai_render_key_bar(); ?> <main> <!-- quick tester --------------------------------------------------- --> <div class="card"> <h2>Live prompt tester</h2> <?php if(!ai_has_key()): ?> <p>Save your OpenAI key above to enable the tester.</p> <?php else: ?> <form method="post" id="frm"> <label for="p">Prompt</label> <textarea id="p" name="prompt" placeholder="Ask anything…" required><?=htmlspecialchars($_POST['prompt']??'')?></textarea> <button id="go">Send to OpenAI</button> <span id="spin"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"/></svg><span id="s">0</span>s</span> </form> <?php if($answer!==''): ?> <h3>Response</h3> <pre><?=htmlspecialchars($answer)?></pre> <?php endif; ?> <?php endif;?> </div> <!-- about card ----------------------------------------------------- --> <div class="card"> <h2>How the connector works</h2> <ul> <li><strong>Your API key never leaves your browser.</strong> It is stored only as an AES‑encrypted cookie. We do <em>not</em> log or transmit keys to our server.</li> <li>OpenAI charges per request. Watch your monthly spend on the <a class="inline" href="https://platform.openai.com/account/usage" target="_blank">usage dashboard ↗</a> and consider setting <a class="inline" href="https://platform.openai.com/account/billing/limits" target="_blank">hard limits ↗</a>.</li> <li>You can delete or swap keys at any time with the red “×” in the black bar.</li> </ul> </div> <!-- developer card ------------------------------------------------- --> <div class="card"> <h2>Developer quick‑start</h2> <p>Building a new Promptinator tool usually takes <em><40 lines</em>.</p> <pre><?php echo htmlspecialchars( '<?php require_once $_SERVER["DOCUMENT_ROOT"]."/openai/init.php"; ai_handle_key_post(); if (!ai_has_key()) { ai_render_key_bar(); exit("save key first"); } ai_render_key_bar(); $answer = ai_chat("Say hello in French", [ "model" => "gpt-4o-mini", "max_tokens" => 60 ]); echo $answer; ?>'); ?></pre> <table> <tr><th>Function</th><th>Purpose</th></tr> <tr><td><code>ai_handle_key_post()</code></td><td>Call once at top; processes Save / Delete actions.</td></tr> <tr><td><code>ai_has_key()</code></td><td>Returns <code>true</code> if user already saved a key.</td></tr> <tr><td><code>ai_render_key_bar()</code></td><td>Outputs the dark bar (model selector, links, etc.).</td></tr> <tr><td><code>ai_chat($prompt, $options)</code></td><td>Sends prompt and returns assistant string.<br> Optional <code>$options</code>: <code>model</code>, <code>temperature</code>, <code>max_tokens</code>.</td></tr> </table> </div> </main> <script> /* spinner for tester --------------------------------------- */ if (document.getElementById('frm')) { const go=document.getElementById('go'),spin=document.getElementById('spin'),s=document.getElementById('s'); document.getElementById('frm').addEventListener('submit',()=>{ go.disabled=true;spin.classList.add('show');let t=0;s.textContent=t; const tick=setInterval(()=>s.textContent=++t,1000); }); } </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel