Site Builder
Editing:
index1111.php
writable 0666
<?php /*-------------------------------------------------------------- * OpenAI “hello‑world” tester • v1.3 (Aug 2025) *------------------------------------------------------------*/ 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 toolbar defaults */ $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;font-weight:600} .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} .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)}} table{width:100%;border-collapse:collapse;margin-top:1rem;font-size:.95rem} th,td{padding:.55rem .7rem;border:1px solid #ccd4e8;text-align:left} </style> </head><body> <!-- breadcrumb --> <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(); ?><!-- universal key / model bar --> <main> <!-- tester --------------------------------------------------------- --> <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> <small> Model, temperature and token limit are taken from the toolbar defaults. Click the <strong>gear icon</strong> next to the model selector if you want to tweak them. </small> <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> <!-- dev notes ------------------------------------------------------ --> <div class="card"> <h2>Developer quick‑start</h2> <p>The toolbar already stores the active model plus defaults; in most tools you can just call <code>ai_chat($prompt)</code> without any extra options.</p> <table> <tr><th>Function</th><th>Purpose</th></tr> <tr><td><code>ai_handle_key_post()</code></td> <td>Process “Save Key” / “× Logout”.</td></tr> <tr><td><code>ai_render_key_bar()</code></td> <td>Draw the black toolbar (key status, model select, gear menu).</td></tr> <tr><td><code>ai_chat($prompt)</code></td> <td>Send prompt using whatever defaults the user picked.</td></tr> </table> </div> </main> <!-- timer for the spinner ----------------------------------------- --> <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).toString(), 1000); frm.addEventListener('ajax-done', () => clearInterval(int), { once:true }); }); } </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel