Site Builder
Editing:
index.php
writable 0666
<?php /*-------------------------------------------------------------- * OpenAI “hello‑world” tester + developer docs *------------------------------------------------------------*/ require_once __DIR__ . '/init.php'; // ① load helper ai_handle_key_post(); // ② handle save / delete $answer = ''; if (ai_has_key() && $_SERVER['REQUEST_METHOD'] === 'POST') { $prompt = trim($_POST['prompt'] ?? ''); if ($prompt !== '') { /* zero‑override — model / temp / tokens come from the helper */ $answer = ai_chat($prompt); } } ?><!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> <!-- minimal page‑only CSS (helper already ships its own styles) --> <style> :root{--bg:#f1f4fb;--card:#fff;--brand:#004cff;--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;width:100%;margin:2rem auto;padding:0 1.2rem;flex:1} .card{background:var(--card);border-radius:var(--radius);box-shadow:0 6px 30px rgba(0,0,0,.08); padding:2rem;margin-top:2rem} .card h2{margin:0 0 1rem} label{font-weight:600;font-size:.95rem;margin-bottom:.4rem;display:block} 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{width:100%;border-collapse:collapse;margin-top:1rem;font-size:.95rem} th,td{padding:.55rem .7rem;border:1px solid #ccd4e8;text-align:left} .spinner{display:none;gap:.5ch;align-items:center;margin-top:1rem} .spinner svg{width:18px;height:18px;animation:rot 1s linear infinite} @keyframes rot{to{transform:rotate(360deg)}} </style> </head><body> <!-- simple breadcrumb (matches the rest of the toolbox) --> <nav class="breadcrumb"> <a href="/members/dashboard.php">Dashboard</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » OpenAI Test <a href="/<?= htmlspecialchars($_SESSION['slug'] ?? '') ?>/" style="float:right">View Site</a> </nav> <?php ai_render_key_bar(); ?><!-- black key bar --> <main> <!-- tester card ----------------------------------------------------- --> <div class="card"> <h2>Live prompt tester</h2> <?php if (!ai_has_key()): ?> <p>Save your OpenAI key above to unlock the tester.</p> <?php else: ?> <form id="tester" method="post" autocomplete="off"> <label for="p">Prompt</label> <textarea id="p" name="prompt" placeholder="Ask anything…" required><?= htmlspecialchars($_POST['prompt'] ?? '') ?></textarea> <button id="send">Send to OpenAI</button> <span class="spinner" 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="sec">0</span>s</span> </form> <?php if ($answer !== ''): ?> <h3>Response</h3> <pre><?= htmlspecialchars($answer) ?></pre> <?php endif; ?> <?php endif; ?> </div> <!-- how it works ---------------------------------------------------- --> <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 never log or proxy it.</li> <li>OpenAI charges per request. Check the <a target="_blank" href="https://platform.openai.com/account/usage">usage dashboard ↗</a> and set <a target="_blank" href="https://platform.openai.com/account/billing/limits"> monthly hard‑limits ↗</a> if needed.</li> <li>Delete / switch keys anytime with the red “×” icon in the bar.</li> </ul> </div> <!-- dev docs -------------------------------------------------------- --> <div class="card"> <h2>Developer quick‑start</h2> <p>Creating 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(); // Step 1 – handle Save / Delete if (!ai_has_key()){ // Step 2 – stop if no key yet ai_render_key_bar(); exit("Save key first"); } ai_render_key_bar(); // draw the bar echo ai_chat("Say hello in French"); // Step 3 – done ?>'); ?></pre> <table> <tr><th>Function</th><th>Purpose</th></tr> <tr><td><code>ai_handle_key_post()</code></td> <td>Process “Save Key” / “× Logout”. Call once at top.</td></tr> <tr><td><code>ai_has_key()</code></td> <td><code>true</code> if a key is already stored.</td></tr> <tr><td><code>ai_render_key_bar()</code></td> <td>Outputs the dark bar (model select, usage link, etc.).</td></tr> <tr><td><code>ai_chat($prompt)</code></td> <td>Sends prompt ⇢ returns assistant string.<br> You may override <code>model</code>, <code>temperature</code>, <code>max_tokens</code> Click the gear next to model selector.</td></tr> </table> </div> </main> <!-- tiny spinner logic --------------------------------------------- --> <script> const frm=document.getElementById('tester'); if(frm){ const btn=document.getElementById('send'), spin=document.getElementById('spin'), sec=document.getElementById('sec'); frm.addEventListener('submit',()=>{ btn.disabled=true; spin.style.display='inline-flex'; let t=0; sec.textContent='0'; const int=setInterval(()=>sec.textContent=++t,1000); frm.addEventListener('ajax-done',()=>clearInterval(int),{once:true}); }); } </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel