<?php
// index.php - Main Layout
session_start();
// === CONFIG ===
$DEFAULT_MODEL = 'deepseek-chat';
$DEFAULT_TEMPERATURE = 0.7;
$DEFAULT_MAXTOKENS = 800;
$MAX_HISTORY_MESSAGES = 12;
// Initialize session defaults
if (!isset($_SESSION['chat_log'])) $_SESSION['chat_log'] = [];
if (!isset($_SESSION['usage_totals'])) $_SESSION['usage_totals'] = ['prompt'=>0,'completion'=>0,'total'=>0];
if (!isset($_SESSION['last_usage'])) $_SESSION['last_usage'] = null;
if (!isset($_SESSION['initial_prompt'])) $_SESSION['initial_prompt'] = 'none';
if (!isset($_SESSION['custom_prompts'])) $_SESSION['custom_prompts'] = [];
// Handle clear chat action
if (isset($_POST['action']) && $_POST['action'] === 'clear_chat') {
$_SESSION['chat_log'] = [];
$_SESSION['usage_totals'] = ['prompt'=>0,'completion'=>0,'total'=>0];
$_SESSION['last_usage'] = null;
}
// Helper function
function h($s){ return htmlspecialchars($s ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
// Sticky UI values
$stickyModel = $_POST['model'] ?? $DEFAULT_MODEL;
$stickyTemp = $_POST['temperature'] ?? $DEFAULT_TEMPERATURE;
$stickyMaxTokens = (int)($_POST['max_tokens'] ?? $DEFAULT_MAXTOKENS);
$chatLog = $_SESSION['chat_log'];
$lastUsage = $_SESSION['last_usage'];
$usageTotals = $_SESSION['usage_totals'];
$initialPrompt = $_SESSION['initial_prompt'];
// Define initial prompt options
$promptOptions = [
'none' => [
'label' => 'No Initial Prompt',
'content' => ''
],
'helpful' => [
'label' => 'Helpful Assistant',
'content' => 'You are a helpful, knowledgeable, and friendly AI assistant. Provide clear, accurate, and detailed responses. Always be respectful and aim to be as useful as possible.'
],
'creative' => [
'label' => 'Creative Partner',
'content' => 'You are a creative and imaginative AI assistant. Help with brainstorming, creative writing, artistic ideas, and innovative solutions. Be inspiring and think outside the box while remaining practical.'
],
'technical' => [
'label' => 'Technical Expert',
'content' => 'You are a technical expert and programming assistant. Provide precise, well-structured code examples, explain technical concepts clearly, and offer best practices. Focus on accuracy and efficiency.'
]
];
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>DeepSeek — General Q&A</title>
<style>
:root{
--bg:#0f1115; --panel:#151823; --ink:#e8e8e8; --muted:#9aa0a6; --br:#252a36;
--accent:#2f6feb; --bot:#2a2f3a; --sep:#2b3242; --code:#0b0e14;
--gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
--glow-color: #4f46e5;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{background:var(--bg);color:var(--ink);font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;display:flex;flex-direction:column}
.header{height:56px;background:var(--panel);border-bottom:1px solid var(--br);display:flex;align-items:center;justify-content:space-between;padding:0 12px}
.title{font-weight:600}
.actions{display:flex;gap:8px}
.btn{background:#1b1f2a;color:var(--ink);border:1px solid var(--br);border-radius:10px;padding:8px 12px;cursor:pointer;font-size:.95rem;text-decoration:none;display:inline-flex;align-items:center}
.btn:hover{border-color:var(--accent)}
.current-prompt-badge {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 0.8rem;
color: var(--accent);
margin-left: 8px;
}
.current-prompt-badge::before {
content: '●';
font-size: 12px;
}
</style>
</head>
<body>
<div class="header">
<div class="title">
DeepSeek — General Q&A
<?php if ($initialPrompt !== 'none'): ?>
<span class="current-prompt-badge"><?= h($promptOptions[$initialPrompt]['label']) ?></span>
<?php endif; ?>
</div>
<div class="actions">
<a href="artifacts.php" class="btn">Artifacts</a>
<form method="post" style="margin:0">
<button class="btn" name="action" value="clear_chat" onclick="return confirm('Clear chat transcript and counters?')">Clear Chat</button>
</form>
<button class="btn" onclick="showSettings()">Settings</button>
</div>
</div>
<?php include 'chat.php'; ?>
<?php include 'settings.php'; ?>
<script>
// Get the current initial prompt from PHP
const currentInitialPrompt = '<?= $initialPrompt ?>';
// Auto-scroll chat to bottom
function autoScroll(){
const wrap = document.querySelector('.chat-wrap');
if (wrap) wrap.scrollTop = wrap.scrollHeight;
}
window.addEventListener('load', autoScroll);
</script>
</body>
</html>