Ares-OS / app.js
jacmor64's picture
Upload folder using huggingface_hub
4cd3bb5 verified
Raw
History Blame Contribute Delete
3.93 kB
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.14.0';
env.allowLocalModels = false;
const chatContainer = document.getElementById('chat-container');
const inputField = document.getElementById('user-input');
const sendBtn = document.getElementById('send-btn');
const verificationModal = document.getElementById('verification-modal');
const codeBlock = document.getElementById('code-block');
const approveBtn = document.getElementById('btn-approve');
const denyBtn = document.getElementById('btn-deny');
let generator;
let isModelLoaded = false;
async function initModel() {
appendMessage('System', 'Loading lightweight quantized neural weights into browser memory...');
try {
// Switching to a smaller, 4-bit quantized model (SmolLM-135M) to fix the "RangeError: offset out of bounds"
// This is a placeholder for the real Ares until you finish training the PyTorch model.
generator = await pipeline('text-generation', 'Xenova/SmolLM-135M-Instruct', {
quantized: true
});
isModelLoaded = true;
appendMessage('System', 'Ares (Demo Core) Ready.');
} catch (e) {
appendMessage('System', 'Error loading weights: ' + e.message);
}
}
function appendMessage(sender, text, type = 'system') {
const msgDiv = document.createElement('div');
msgDiv.classList.add('message', type);
msgDiv.innerHTML = `<strong>[${sender}]</strong> ${text}`;
chatContainer.appendChild(msgDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
async function handleAresLogic(userText) {
if (userText.toLowerCase().includes("build a tool") || userText.toLowerCase().includes("code")) {
triggerXiphos(userText);
return;
}
if (!isModelLoaded) {
appendMessage('Ares', 'Neural pathways are still initializing...', 'ares');
return;
}
appendMessage('Ares', '*Thinking...*', 'ares');
// Formatting prompt for SmolLM Instruct
const prompt = `<|im_start|>user\n${userText}<|im_end|>\n<|im_start|>assistant\n`;
try {
const output = await generator(prompt, {
max_new_tokens: 64,
temperature: 0.7,
repetition_penalty: 1.1,
do_sample: true
});
chatContainer.lastChild.remove();
let responseText = output[0].generated_text.split('<|im_start|>assistant\n')[1] || output[0].generated_text;
responseText = responseText.replace(/<\|im_end\|>/g, '').trim();
appendMessage('Ares', responseText, 'ares');
} catch(e) {
chatContainer.lastChild.remove();
appendMessage('System', 'Inference failed: ' + e.message, 'system');
}
}
function triggerXiphos(task) {
appendMessage('Xiphos', `I am analyzing your request to build a tool for: "${task}"`, 'xiphos');
setTimeout(() => {
const mockCode = `def dynamic_tool():\n # Built by Xiphos\n print("Executing new capability...")\n return True`;
codeBlock.innerText = mockCode;
verificationModal.classList.remove('hidden');
}, 1000);
}
sendBtn.addEventListener('click', () => {
const text = inputField.value.trim();
if (!text) return;
appendMessage('User', text, 'user');
inputField.value = '';
handleAresLogic(text);
});
inputField.addEventListener('keypress', (e) => {
if (e.key === 'Enter') sendBtn.click();
});
approveBtn.addEventListener('click', () => {
verificationModal.classList.add('hidden');
appendMessage('Xiphos', 'Code verified by User. Tool added to database.', 'xiphos');
appendMessage('Ares', 'I have integrated the new tool. Ready to proceed.', 'ares');
});
denyBtn.addEventListener('click', () => {
verificationModal.classList.add('hidden');
appendMessage('Xiphos', 'Code rejected. Scrapping blueprint.', 'xiphos');
});
initModel();