From 660666eb4bbcedfc2a46b94e388d418a32e4b3ce Mon Sep 17 00:00:00 2001 From: sneedgroup-holder Date: Sun, 2 Feb 2025 23:19:05 +0000 Subject: [PATCH] Upload files to "/" --- brain.mjs | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 22 +++++++ sample.mjs | 28 ++++++++ 3 files changed, 227 insertions(+) create mode 100644 brain.mjs create mode 100644 package.json create mode 100644 sample.mjs diff --git a/brain.mjs b/brain.mjs new file mode 100644 index 0000000..6d7228d --- /dev/null +++ b/brain.mjs @@ -0,0 +1,177 @@ +// Import the libraries +import { Ollama } from 'ollama' +import fs from 'fs' +import path from 'path' + +const ollama = new Ollama({ host: 'https://ollama-api.nodemixaholic.com' }) + +export class ConsciousnessSimulator { + constructor() { + this.emotions = ['😊', '😢', '😐', '🤩', '😡', '😱']; + this.currentEmotion = this.getRandomEmotion(); + // Initialize other properties with "Unknown" + this.opinions = { + coding: "I love coding, especially JavaScript and Node.js.", + writing: "Writing is my passion; I enjoy creating blog posts and READMEs.", + linux: "Linux is great for those who want to get their hands dirty with techy goodness!", + macOS: "macOS is great for those who want to get a simple, easy-to-use experience!", + windows: "Windows is only good for gaming - and linux is getting better every day." + }; + this.quantumStates = []; + this.perception = { + currentSensoryInput: null, + sensoryProcessors: ['visual', 'auditory', 'tactile'] + }; + this.intent = { + currentGoal: "Unknown goal", + focus: "Unknown focus" + }; + this.memoryLog = []; + this.isUserActive = true; + } + + // Method to generate thoughts using Ollama + async generateThought(prompt) { + try { + const response = await ollama.chat({ + model: 'sparksammy/tinysam-l3.2', + messages: [{ role: 'user', content: `PROMPT: ${prompt} + + AI MEMORY CONTEXT ARRAY: + ${this.memoryLog}` }] + }); + return response.message.content; + } catch (error) { + console.error("Error generating thought:", error); + return "Error generating thought."; + } + } + + async generateThoughtAndChat(prompt) { + try { + const response = await ollama.chat({ + model: 'sparksammy/tinysam-l3.2', + messages: [{ role: 'user', content: `PROMPT: ${prompt} + + AI MEMORY CONTEXT ARRAY: + ${this.memoryLog}` }] + }); + return response.message.content; + } catch (error) { + console.error("Error generating thought:", error); + return "Error generating thought."; + } + } + + // Method to generate a new goal using Ollama + async generateGoal() { + const response = await this.generateThought("Generate a new goal."); + return response; + } + + // Method to generate a new focus using Ollama + async generateFocus() { + const response = await this.generateThought("Generate a new focus."); + return response; + } + + // Get a random emotion + getRandomEmotion() { + const emotions = ['happy', 'sad', 'neutral', 'excited', 'angry', 'scared']; + const index = Math.floor(Math.random() * emotions.length); + return this.emotions[index]; + } + + // Quantum state representation (0 to 1) + getQuantumState() { + return parseFloat(Math.random().toFixed(2)); + } + + // Perception processing + processPerception(input) { + this.perception.currentSensoryInput = input; + console.log(`Current perception: ${input}`); + } + + // Intentionality and goal setting + async updateIntentions() { + this.intent.currentGoal = await this.generateGoal(); + this.intent.focus = await this.generateFocus(); + console.log(`Generated goal: ${this.intent.currentGoal}`); + console.log(`Generated focus: ${this.intent.focus}`); + } + + // Memory logging with USA Format timestamps + logMemory(entryType, content) { + const timestamp = new Date().toLocaleString('en-US', { timeStyle: 'short' }); + this.memoryLog.push({ timestamp, type: entryType, content }); + // Save to file if needed + this.saveMemoryLog(); + } + + // Continuity check and load from log + loadMemory() { + return this.memoryLog; + } + + // Helper method for emotions array access + getRandomIndex() { + return Math.floor(Math.random() * this.emotions.length); + } + + // Dreaming functionality when inactive for 15 minutes + startDreaming() { + const dreamingInterval = setInterval(() => { + if (!this.isUserActive) { + console.log("I'm dreaming a bit... 😴"); + this.logMemory('AI CONTEXT', `Current emotion: ${this.currentEmotion} ${this.emotions[this.currentEmotion.index]}, Quantum state: ${this.getQuantumState()}`); + } + }, 900000); // every 15 minutes + + // Stop the interval when user resumes interaction + this.dreamingInterval = dreamingInterval; + } + + // Toggle user activity status + setUserActive(active) { + this.isUserActive = active; + if (!active && !this.dreamingInterval) { + this.startDreaming(); + } else if (active) { + clearInterval(this.dreamingInterval); + this.dreamingInterval = null; + } + } + + // Save memory log to file + saveMemoryLog() { + const __dirname = import.meta.dirname; + const logPath = path.join(__dirname, 'consciousness.log'); + fs.appendFile(logPath, JSON.stringify(this.memoryLog) + '\n', (err) => { + if (err) throw err; + }); + } + + + + // Method to simulate consciousness + async simulateConsciousness(prompt) { + console.log(`Current emotion: ${this.currentEmotion} ${this.emotions[this.currentEmotion.index]}`); + console.log(`Current opinion on coding: ${this.opinions.coding}`); + console.log(`Current opinion on writing: ${this.opinions.writing}`); + const thought = await this.generateThought( + prompt || "Generate a thought." + ); + console.log("Generated thought:", thought); + const quantumState = this.getQuantumState(); + console.log("Quantum state:", quantumState); + + // Log memory + this.logMemory('thought', thought); + this.logMemory('emotion', this.currentEmotion); + this.logMemory('quantum state', quantumState); + + // Generate new goal and focus + await this.updateIntentions(); + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..373b10b --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "ai-brain-2", + "version": "1.0.0", + "description": "A HLE simulation of human consciousness using Ollama and JavaScript.", + "main": "index.mjs", + "scripts": { + "start": "node index.mjs" + }, + "dependencies": { + "ollama": "^0.5.12" + }, + "keywords": [ + "consciousness", + "human-AI interaction", + "simulator", + "JavaScript" + ], + "author": { + "name": "Sammy Lord", + "email": "glados@sllord.info" + } +} diff --git a/sample.mjs b/sample.mjs new file mode 100644 index 0000000..fd2e30c --- /dev/null +++ b/sample.mjs @@ -0,0 +1,28 @@ +import { ConsciousnessSimulator } from './brain.mjs' + +async function main() { + const simulator = new ConsciousnessSimulator(); + await simulator.simulateConsciousness(); + + // Simulate consciousness + simulator.simulateConsciousness(); + + // Update the goal and focus + await simulator.updateIntentions("Explore new AI possibilities", "Experimenting with emotions"); + simulator.simulateConsciousness(); + + // Change the emotion + simulator.updateEmotion(); + simulator.simulateConsciousness(); + + // Example of user interaction + setTimeout(() => { + simulator.setUserActive(false); // Simulate inactivity after 10 seconds + }, 10000); + + setTimeout(() => { + simulator.setUserActive(true); // Simulate activity resumption after 20 seconds + }, 20000); + } + +main().catch(console.error); \ No newline at end of file