Site Builder
Editing:
index22.php
writable 0666
<?php /* /openai/index.php * Simple “Hello OpenAI” tester that re‑uses openai/init.php */ require_once __DIR__.'/init.php'; // ① load key bar + ai_chat( ) ai_handle_key_post(); // ② handle save/delete actions $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 Test • 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)} 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.6rem} #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} </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="/<?= $_SESSION['slug']??''?>/" style="float:right">View Site</a> </nav> <?php /* ③ render the dark key bar. (shows form if no key saved) */ ai_render_key_bar(); ?> <main> <div class="card"> <h2 style="margin-top:0">Quick prompt test</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> <input type="hidden" name="model" value="<?=htmlspecialchars($_POST['model']??'gpt-4o-mini')?>"> <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> </main> <script> /* simple spinner & second counter (works without JS too) */ 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