Update gpt/index.html
This commit is contained in:
+599
-84
@@ -1,164 +1,679 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Neural Terminal</title>
|
<title>NEURAL-NET TERMINAL v2.1</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
/* ============================================
|
||||||
|
AI BACKEND CONFIGURATION
|
||||||
|
Edit these settings to connect your AI
|
||||||
|
============================================ */
|
||||||
|
:root {
|
||||||
|
--crt-green: #33ff66;
|
||||||
|
--crt-green-dim: #1a8033;
|
||||||
|
--crt-green-bright: #66ff99;
|
||||||
|
--crt-bg: #0a0a0a;
|
||||||
|
--crt-bg-light: #0f1a0f;
|
||||||
|
--crt-border: #1a3d1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background: #050805;
|
padding: 0;
|
||||||
color: #33ff66;
|
box-sizing: border-box;
|
||||||
font-family: monospace;
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Terminal';
|
||||||
|
src: local('Courier New'), local('Consolas'), local('monospace');
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--crt-bg);
|
||||||
|
color: var(--crt-green);
|
||||||
|
font-family: 'Courier New', Consolas, monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.4;
|
||||||
|
min-height: 100vh;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.screen {
|
/* CRT Screen Effect */
|
||||||
|
.crt-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crt-overlay::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: repeating-linear-gradient(
|
||||||
|
0deg,
|
||||||
|
rgba(0, 0, 0, 0.15) 0px,
|
||||||
|
rgba(0, 0, 0, 0.15) 1px,
|
||||||
|
transparent 1px,
|
||||||
|
transparent 2px
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.crt-overlay::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background: radial-gradient(
|
||||||
|
ellipse at center,
|
||||||
|
transparent 0%,
|
||||||
|
rgba(0, 0, 0, 0.3) 100%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminal Container */
|
||||||
|
.terminal {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Header */
|
||||||
.header {
|
.header {
|
||||||
padding: 8px;
|
border: 1px solid var(--crt-green-dim);
|
||||||
border-bottom: 1px solid #1a3320;
|
padding: 8px 12px;
|
||||||
font-size: 12px;
|
margin-bottom: 8px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header-title {
|
||||||
|
font-weight: bold;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-status {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--crt-green-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-indicator {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--crt-green-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot.online {
|
||||||
|
background: var(--crt-green);
|
||||||
|
box-shadow: 0 0 6px var(--crt-green);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot.offline {
|
||||||
|
background: #ff3333;
|
||||||
|
box-shadow: 0 0 6px #ff3333;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Output Area */
|
||||||
.output {
|
.output {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 10px;
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
white-space: pre-wrap;
|
border: 1px solid var(--crt-green-dim);
|
||||||
|
padding: 12px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
scrollbar-width: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inputBar {
|
.output::-webkit-scrollbar {
|
||||||
border-top: 1px solid #1a3320;
|
display: none;
|
||||||
padding: 10px;
|
}
|
||||||
|
|
||||||
|
.output-line {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-line.user {
|
||||||
|
color: var(--crt-green-bright);
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-line.user::before {
|
||||||
|
content: '> ';
|
||||||
|
color: var(--crt-green-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-line.system {
|
||||||
|
color: var(--crt-green-dim);
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-line.ai {
|
||||||
|
color: var(--crt-green);
|
||||||
|
padding-left: 2ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-line.error {
|
||||||
|
color: #ff6666;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Input Area */
|
||||||
|
.input-area {
|
||||||
|
border: 1px solid var(--crt-green-dim);
|
||||||
|
padding: 8px 12px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
.input-prompt {
|
||||||
|
color: var(--crt-green);
|
||||||
|
font-weight: bold;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-field {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
color: #33ff66;
|
color: var(--crt-green);
|
||||||
font-family: monospace;
|
font-family: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
caret-color: var(--crt-green);
|
||||||
|
caret-shape: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.system { color: #1a8033; }
|
.input-field::placeholder {
|
||||||
.error { color: #ff3333; }
|
color: var(--crt-green-dim);
|
||||||
.user { color: #33ff66; }
|
}
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
|
.footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 4px 0;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--crt-green-dim);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Config Panel */
|
||||||
|
.config-panel {
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
background: var(--crt-bg);
|
||||||
|
border: 2px solid var(--crt-green);
|
||||||
|
padding: 20px;
|
||||||
|
z-index: 100;
|
||||||
|
min-width: 400px;
|
||||||
|
max-width: 90vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-panel.visible {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-panel h2 {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
font-size: 14px;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-group {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: var(--crt-green-dim);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-group input,
|
||||||
|
.config-group select {
|
||||||
|
width: 100%;
|
||||||
|
background: var(--crt-bg-light);
|
||||||
|
border: 1px solid var(--crt-green-dim);
|
||||||
|
color: var(--crt-green);
|
||||||
|
padding: 6px 8px;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-group input:focus,
|
||||||
|
.config-group select:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--crt-green);
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-btn {
|
||||||
|
flex: 1;
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid var(--crt-green-dim);
|
||||||
|
color: var(--crt-green);
|
||||||
|
padding: 8px;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-btn:hover {
|
||||||
|
background: var(--crt-green-dim);
|
||||||
|
color: var(--crt-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-btn.primary {
|
||||||
|
border-color: var(--crt-green);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Screen flicker animation */
|
||||||
|
@keyframes flicker {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
92% { opacity: 1; }
|
||||||
|
93% { opacity: 0.8; }
|
||||||
|
94% { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal {
|
||||||
|
animation: flicker 8s infinite;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="screen">
|
<div class="crt-overlay"></div>
|
||||||
|
|
||||||
|
<div class="terminal">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<span>NEURAL TERMINAL v1.0</span>
|
<span class="header-title">NEURAL-NET TERMINAL v2.1</span>
|
||||||
<span id="status">AI: OFFLINE</span>
|
<div class="header-status">
|
||||||
<span id="date"></span>
|
<div class="status-indicator">
|
||||||
|
<span class="status-dot" id="statusDot"></span>
|
||||||
|
<span id="statusText">OFFLINE</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="out" class="output"></div>
|
<div class="output" id="output">
|
||||||
|
<div class="output-line system">NEURAL-NET TERMINAL v2.1 initialized</div>
|
||||||
<div class="inputBar">
|
<div class="output-line system">Type 'help' for available commands</div>
|
||||||
<span>>></span>
|
<div class="output-line system">Type 'config' to configure AI backend</div>
|
||||||
<input id="cmd" autocomplete="off" />
|
<div class="output-line system">─────────────────────────────────────</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="input-area">
|
||||||
|
<span class="input-prompt">$</span>
|
||||||
|
<input type="text" class="input-field" id="inputField" placeholder="Enter command..." autofocus>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<span>COMMANDS: help | config | clear | status</span>
|
||||||
|
<span id="timeDisplay"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Config Panel -->
|
||||||
|
<div class="config-panel" id="configPanel">
|
||||||
|
<h2>[ AI BACKEND CONFIGURATION ]</h2>
|
||||||
|
|
||||||
|
<div class="config-group">
|
||||||
|
<label>PRESET</label>
|
||||||
|
<select id="presetSelect">
|
||||||
|
<option value="custom">Custom</option>
|
||||||
|
<option value="ollama">Ollama (localhost:11434)</option>
|
||||||
|
<option value="lmstudio">LM Studio (localhost:1234)</option>
|
||||||
|
<option value="gpt4all">GPT4All (localhost:4891)</option>
|
||||||
|
<option value="openai">OpenAI API</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="config-group">
|
||||||
|
<label>ENDPOINT URL</label>
|
||||||
|
<input type="text" id="endpointInput" placeholder="http://localhost:11434/api/chat">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="config-group">
|
||||||
|
<label>MODEL NAME</label>
|
||||||
|
<input type="text" id="modelInput" placeholder="llama2">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="config-group">
|
||||||
|
<label>API KEY (optional)</label>
|
||||||
|
<input type="password" id="apiKeyInput" placeholder="Leave empty for local models">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="config-buttons">
|
||||||
|
<button class="config-btn" onclick="closeConfig()">CANCEL</button>
|
||||||
|
<button class="config-btn" onclick="testConnection()">TEST</button>
|
||||||
|
<button class="config-btn primary" onclick="saveConfig()">SAVE</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const AI = {
|
/* ============================================
|
||||||
|
AI CONFIGURATION
|
||||||
|
============================================ */
|
||||||
|
let aiConfig = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
endpoint: "http://localhost:11434/api/chat",
|
endpoint: '',
|
||||||
model: "llama2",
|
model: '',
|
||||||
apiType: "ollama"
|
apiKey: '',
|
||||||
|
type: 'ollama' // ollama, openai, lmstudio, gpt4all
|
||||||
};
|
};
|
||||||
|
|
||||||
const out = document.getElementById("out");
|
// Load saved config
|
||||||
const cmd = document.getElementById("cmd");
|
const savedConfig = localStorage.getItem('neuralTerminalConfig');
|
||||||
|
if (savedConfig) {
|
||||||
document.getElementById("date").textContent =
|
aiConfig = JSON.parse(savedConfig);
|
||||||
new Date().toLocaleString();
|
|
||||||
|
|
||||||
function log(text, cls="system") {
|
|
||||||
const div = document.createElement("div");
|
|
||||||
div.className = cls;
|
|
||||||
div.textContent = text;
|
|
||||||
out.appendChild(div);
|
|
||||||
out.scrollTop = out.scrollHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function askAI(prompt) {
|
/* ============================================
|
||||||
if (!AI.enabled) {
|
TERMINAL STATE
|
||||||
log("AI OFFLINE", "error");
|
============================================ */
|
||||||
|
const output = document.getElementById('output');
|
||||||
|
const inputField = document.getElementById('inputField');
|
||||||
|
const statusDot = document.getElementById('statusDot');
|
||||||
|
const statusText = document.getElementById('statusText');
|
||||||
|
const timeDisplay = document.getElementById('timeDisplay');
|
||||||
|
const configPanel = document.getElementById('configPanel');
|
||||||
|
|
||||||
|
let commandHistory = [];
|
||||||
|
let historyIndex = -1;
|
||||||
|
let isProcessing = false;
|
||||||
|
|
||||||
|
/* ============================================
|
||||||
|
UI FUNCTIONS
|
||||||
|
============================================ */
|
||||||
|
function updateStatus() {
|
||||||
|
if (aiConfig.enabled) {
|
||||||
|
statusDot.className = 'status-dot online';
|
||||||
|
statusText.textContent = 'ONLINE';
|
||||||
|
} else {
|
||||||
|
statusDot.className = 'status-dot offline';
|
||||||
|
statusText.textContent = 'OFFLINE';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTime() {
|
||||||
|
const now = new Date();
|
||||||
|
timeDisplay.textContent = now.toLocaleTimeString('en-US', { hour12: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLine(text, type = '') {
|
||||||
|
const line = document.createElement('div');
|
||||||
|
line.className = 'output-line' + (type ? ' ' + type : '');
|
||||||
|
line.textContent = text;
|
||||||
|
output.appendChild(line);
|
||||||
|
output.scrollTop = output.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearOutput() {
|
||||||
|
output.innerHTML = '';
|
||||||
|
addLine('Screen cleared', 'system');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ============================================
|
||||||
|
CONFIG PANEL
|
||||||
|
============================================ */
|
||||||
|
function openConfig() {
|
||||||
|
document.getElementById('endpointInput').value = aiConfig.endpoint;
|
||||||
|
document.getElementById('modelInput').value = aiConfig.model;
|
||||||
|
document.getElementById('apiKeyInput').value = aiConfig.apiKey;
|
||||||
|
configPanel.classList.add('visible');
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeConfig() {
|
||||||
|
configPanel.classList.remove('visible');
|
||||||
|
inputField.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveConfig() {
|
||||||
|
aiConfig.endpoint = document.getElementById('endpointInput').value.trim();
|
||||||
|
aiConfig.model = document.getElementById('modelInput').value.trim();
|
||||||
|
aiConfig.apiKey = document.getElementById('apiKeyInput').value.trim();
|
||||||
|
aiConfig.enabled = aiConfig.endpoint !== '' && aiConfig.model !== '';
|
||||||
|
|
||||||
|
localStorage.setItem('neuralTerminalConfig', JSON.stringify(aiConfig));
|
||||||
|
updateStatus();
|
||||||
|
closeConfig();
|
||||||
|
addLine('Configuration saved', 'system');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testConnection() {
|
||||||
|
const endpoint = document.getElementById('endpointInput').value.trim();
|
||||||
|
const model = document.getElementById('modelInput').value.trim();
|
||||||
|
|
||||||
|
if (!endpoint || !model) {
|
||||||
|
alert('Please enter endpoint and model name');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(AI.endpoint, {
|
try {
|
||||||
method: "POST",
|
// Try a simple request based on detected type
|
||||||
headers: {"Content-Type":"application/json"},
|
const testEndpoint = endpoint.replace('/chat', '/tags').replace('/completions', '/models');
|
||||||
|
const response = await fetch(testEndpoint, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: aiConfig.apiKey ? { 'Authorization': 'Bearer ' + aiConfig.apiKey } : {}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
alert('Connection successful!');
|
||||||
|
} else {
|
||||||
|
alert('Connection failed: ' + response.status);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
alert('Connection error: ' + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preset handling
|
||||||
|
document.getElementById('presetSelect').addEventListener('change', function() {
|
||||||
|
const presets = {
|
||||||
|
ollama: { endpoint: 'http://localhost:11434/api/chat', model: 'llama2', type: 'ollama' },
|
||||||
|
lmstudio: { endpoint: 'http://localhost:1234/v1/chat/completions', model: 'local-model', type: 'openai' },
|
||||||
|
gpt4all: { endpoint: 'http://localhost:4891/v1/chat/completions', model: 'gpt4all-model', type: 'openai' },
|
||||||
|
openai: { endpoint: 'https://api.openai.com/v1/chat/completions', model: 'gpt-3.5-turbo', type: 'openai' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const preset = presets[this.value];
|
||||||
|
if (preset) {
|
||||||
|
document.getElementById('endpointInput').value = preset.endpoint;
|
||||||
|
document.getElementById('modelInput').value = preset.model;
|
||||||
|
aiConfig.type = preset.type;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ============================================
|
||||||
|
AI COMMUNICATION
|
||||||
|
============================================ */
|
||||||
|
async function queryAI(message) {
|
||||||
|
if (!aiConfig.enabled) {
|
||||||
|
addLine('', '');
|
||||||
|
addLine('The AI you are trying to reach is not online at the moment.', 'error');
|
||||||
|
addLine('', '');
|
||||||
|
addLine('To connect an AI backend:', 'system');
|
||||||
|
addLine(' 1. Type "config" to open settings', 'system');
|
||||||
|
addLine(' 2. Choose a preset or enter custom endpoint', 'system');
|
||||||
|
addLine(' 3. Supported: Ollama, LM Studio, GPT4All, OpenAI', 'system');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isProcessing = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let response;
|
||||||
|
|
||||||
|
if (aiConfig.type === 'ollama') {
|
||||||
|
response = await fetch(aiConfig.endpoint, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: AI.model,
|
model: aiConfig.model,
|
||||||
messages: [{role:"user", content: prompt}],
|
messages: [{ role: 'user', content: message }],
|
||||||
stream: false
|
stream: false
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await response.json();
|
||||||
const text =
|
if (data.message && data.message.content) {
|
||||||
data.message?.content ||
|
addLine(data.message.content, 'ai');
|
||||||
data.choices?.[0]?.message?.content ||
|
} else if (data.error) {
|
||||||
"no response";
|
addLine('Error: ' + data.error, 'error');
|
||||||
|
|
||||||
log(text, "system");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.addEventListener("keydown", async (e) => {
|
} else {
|
||||||
if (e.key !== "Enter") return;
|
// OpenAI-compatible API (LM Studio, GPT4All, OpenAI, etc.)
|
||||||
|
const headers = { 'Content-Type': 'application/json' };
|
||||||
|
if (aiConfig.apiKey) {
|
||||||
|
headers['Authorization'] = 'Bearer ' + aiConfig.apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
const val = cmd.value.trim();
|
response = await fetch(aiConfig.endpoint, {
|
||||||
cmd.value = "";
|
method: 'POST',
|
||||||
|
headers: headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: aiConfig.model,
|
||||||
|
messages: [{ role: 'user', content: message }],
|
||||||
|
stream: false
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
if (!val) return;
|
const data = await response.json();
|
||||||
|
if (data.choices && data.choices[0]) {
|
||||||
|
addLine(data.choices[0].message.content, 'ai');
|
||||||
|
} else if (data.error) {
|
||||||
|
addLine('Error: ' + (data.error.message || data.error), 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log("> " + val, "user");
|
} catch (e) {
|
||||||
|
addLine('Connection error: ' + e.message, 'error');
|
||||||
|
addLine('Make sure your AI backend is running', 'system');
|
||||||
|
}
|
||||||
|
|
||||||
switch(val.toLowerCase()) {
|
isProcessing = false;
|
||||||
case "clear":
|
}
|
||||||
out.innerHTML = "";
|
|
||||||
|
/* ============================================
|
||||||
|
COMMAND PROCESSING
|
||||||
|
============================================ */
|
||||||
|
function processCommand(input) {
|
||||||
|
const trimmed = input.trim();
|
||||||
|
if (!trimmed) return;
|
||||||
|
|
||||||
|
addLine(trimmed, 'user');
|
||||||
|
commandHistory.unshift(trimmed);
|
||||||
|
historyIndex = -1;
|
||||||
|
|
||||||
|
const cmd = trimmed.toLowerCase();
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case 'help':
|
||||||
|
addLine('', '');
|
||||||
|
addLine('Available commands:', 'system');
|
||||||
|
addLine(' help - Show this help', 'system');
|
||||||
|
addLine(' config - Configure AI backend', 'system');
|
||||||
|
addLine(' status - Show connection status', 'system');
|
||||||
|
addLine(' clear - Clear screen', 'system');
|
||||||
|
addLine(' date - Show current date/time', 'system');
|
||||||
|
addLine('', '');
|
||||||
|
addLine('Any other input is sent to the AI', 'system');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "status":
|
case 'config':
|
||||||
log("AI: " + (AI.enabled ? "ONLINE" : "OFFLINE"));
|
openConfig();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "help":
|
case 'status':
|
||||||
log("commands: help, clear, status, date, about");
|
addLine('', '');
|
||||||
|
addLine('CONNECTION STATUS:', 'system');
|
||||||
|
addLine(' Enabled: ' + (aiConfig.enabled ? 'YES' : 'NO'), 'system');
|
||||||
|
addLine(' Endpoint: ' + (aiConfig.endpoint || 'Not configured'), 'system');
|
||||||
|
addLine(' Model: ' + (aiConfig.model || 'Not configured'), 'system');
|
||||||
|
addLine(' Type: ' + (aiConfig.type || 'unknown'), 'system');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "date":
|
case 'clear':
|
||||||
log(new Date().toString());
|
clearOutput();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "about":
|
case 'date':
|
||||||
log("Neural Terminal single-file build");
|
addLine(new Date().toString(), 'system');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
await askAI(val);
|
queryAI(trimmed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ============================================
|
||||||
|
INPUT HANDLING
|
||||||
|
============================================ */
|
||||||
|
inputField.addEventListener('keydown', function(e) {
|
||||||
|
if (e.key === 'Enter' && !isProcessing) {
|
||||||
|
processCommand(this.value);
|
||||||
|
this.value = '';
|
||||||
|
} else if (e.key === 'ArrowUp') {
|
||||||
|
e.preventDefault();
|
||||||
|
if (historyIndex < commandHistory.length - 1) {
|
||||||
|
historyIndex++;
|
||||||
|
this.value = commandHistory[historyIndex];
|
||||||
|
}
|
||||||
|
} else if (e.key === 'ArrowDown') {
|
||||||
|
e.preventDefault();
|
||||||
|
if (historyIndex > 0) {
|
||||||
|
historyIndex--;
|
||||||
|
this.value = commandHistory[historyIndex];
|
||||||
|
} else {
|
||||||
|
historyIndex = -1;
|
||||||
|
this.value = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cmd.focus();
|
/* ============================================
|
||||||
</script>
|
INITIALIZATION
|
||||||
|
============================================ */
|
||||||
|
updateStatus();
|
||||||
|
updateTime();
|
||||||
|
setInterval(updateTime, 1000);
|
||||||
|
inputField.focus();
|
||||||
|
|
||||||
|
// Click anywhere to focus input
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (!configPanel.contains(e.target)) {
|
||||||
|
inputField.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user