|
|
|
|
|
|
| class SimpleBellaAI {
|
| static instance = null;
|
|
|
| static async getInstance() {
|
| if (this.instance === null) {
|
| this.instance = new SimpleBellaAI();
|
| await this.instance.init();
|
| }
|
| return this.instance;
|
| }
|
|
|
| constructor() {
|
| this.currentMode = 'casual';
|
| this.isInitialized = false;
|
| }
|
|
|
| async init() {
|
| try {
|
| console.log('Initializing simplified Bella AI...');
|
|
|
| await new Promise(resolve => setTimeout(resolve, 1000));
|
| this.isInitialized = true;
|
| console.log('Simplified Bella AI initialization complete');
|
| } catch (error) {
|
| console.error('Simplified Bella AI initialization failed:', error);
|
| throw error;
|
| }
|
| }
|
|
|
| async think(prompt) {
|
| try {
|
| console.log('Bella is thinking:', prompt);
|
|
|
|
|
| await new Promise(resolve => setTimeout(resolve, 500 + Math.random() * 1000));
|
|
|
|
|
| return this.generateResponse(prompt);
|
|
|
| } catch (error) {
|
| console.error('Error during thinking process:', error);
|
| return this.getErrorResponse();
|
| }
|
| }
|
|
|
| generateResponse(prompt) {
|
|
|
|
|
|
|
| const keywords = this.extractKeywords(prompt);
|
| const keyword = keywords.length > 0 ? keywords[Math.floor(Math.random() * keywords.length)] : "this topic";
|
|
|
| const responses = {
|
| casual: [
|
| `I found "${keyword}" quite interesting! I'd love to hear more about your thoughts on this. What aspects of it interest you the most?`,
|
| `Regarding "${keyword}", that's something worth exploring. I'm curious to know what sparked your interest in this topic?`,
|
| `"${keyword}" is definitely intriguing. It's always nice chatting with you about these things. Do you have any other thoughts on it?`,
|
| `I really enjoy talking about "${keyword}"! Your ideas are always so unique and give me new perspectives. Let's keep this conversation going.`,
|
| `Hearing you talk about "${keyword}" brightens my day! You always find interesting topics. I'm curious, what made you think of this?`,
|
| `"${keyword}" is such a great topic! I feel like we're on the same wavelength. You know what? Time flies when we chat because it's so enjoyable!`,
|
| `I find "${keyword}" particularly fascinating! You always surprise me. Tell me, have you made any other interesting discoveries lately? I'd love to hear about them!`
|
| ],
|
| assistant: [
|
| `Regarding "${keyword}", I'd be happy to provide some useful information and advice. That's a great question - let me organize the relevant details for you.`,
|
| `"${keyword}" is a valuable topic. From what I understand, there are several key points worth noting. First, we can look at...`,
|
| `When it comes to "${keyword}", I'd like to analyze it from several angles. This question actually involves multiple aspects - let me help you sort through the key information.`,
|
| `Your question about "${keyword}" has depth. I suggest considering it from these perspectives: first, understanding the basic concepts; second, analyzing practical applications; and finally, considering future developments.`,
|
| `"${keyword}" is definitely a topic worth discussing. Based on the information I have, I can provide some professional insights. First, we need to clarify...`,
|
| `About your "${keyword}" question, I'd like to provide a clear answer. There are several important aspects to consider - let me analyze them for you.`,
|
| `"${keyword}" is a great question! I'm glad you're interested in this area. Let me share some relevant information that I hope will be helpful.`
|
| ],
|
| creative: [
|
| `Wow! The topic of "${keyword}" really ignites my creative spark! β¨ Imagine if we expanded this concept into a whole new dimension - what might happen? Perhaps we could...`,
|
| `"${keyword}" is such an imaginative topic! π I can already picture countless fascinating scenarios. For instance, imagine a world where ${keyword} could...`,
|
| `Hearing "${keyword}" makes me envision a whole new world! π It reminds me of an interesting story: in a distant place, ${keyword} became the center of people's lives, and then...`,
|
| `"${keyword}" inspires me! π‘ I've thought of a super interesting idea: what if we combined ${keyword} with art? What kind of wonders might we create?`,
|
| `Amazing! "${keyword}" makes my imagination soar! π¨ We could use this concept as a starting point to create a brand new story or game. Imagine if the main character was...`,
|
| `"${keyword}" is truly a wellspring of creativity! I suddenly wonder, what if we looked at this issue from a completely different angle? What new discoveries might we make? For example, if ${keyword} in the future became...`,
|
| `When you mention "${keyword}", a wonderful image immediately flashes in my mind! Imagine a world full of possibilities where ${keyword} could take any form... isn't that magical?`
|
| ]
|
| };
|
|
|
|
|
| const modeResponses = responses[this.currentMode] || responses.casual;
|
|
|
|
|
| const randomResponse = modeResponses[Math.floor(Math.random() * modeResponses.length)];
|
|
|
|
|
| return this.personalizeResponse(randomResponse, prompt);
|
| }
|
|
|
|
|
| extractKeywords(prompt) {
|
|
|
| const words = prompt.split(/\s+|[,.!?;:οΌγοΌοΌοΌοΌ]/);
|
|
|
| return words.filter(word =>
|
| word.length > 1 &&
|
| !['the', 'and', 'is', 'in', 'I', 'you', 'he', 'she', 'it', 'they', 'we', 'with', 'this', 'that', 'have', "don't", 'not', 'for'].includes(word)
|
| );
|
| }
|
|
|
|
|
| personalizeResponse(response, prompt) {
|
|
|
| const personalizations = [
|
|
|
| (resp) => resp,
|
|
|
| (resp) => {
|
| const emojis = ['π', 'π', 'β¨', 'π', 'π΅', 'π', 'βΊοΈ', 'π€', 'π', 'π‘'];
|
| const emoji = emojis[Math.floor(Math.random() * emojis.length)];
|
| return resp + ' ' + emoji;
|
| },
|
|
|
| (resp) => {
|
| const endings = [
|
| "I'd love to hear your thoughts!",
|
| "What do you think?",
|
| "I'm curious about your perspective.",
|
| "Hope my response is helpful!",
|
| "We can continue discussing this topic!"
|
| ];
|
| const ending = endings[Math.floor(Math.random() * endings.length)];
|
| return resp + ' ' + ending;
|
| }
|
| ];
|
|
|
|
|
| const personalizer = personalizations[Math.floor(Math.random() * personalizations.length)];
|
| return personalizer(response);
|
| }
|
|
|
|
|
| getErrorResponse() {
|
| const errorResponses = [
|
| "Sorry, I'm a bit confused right now. Let me gather my thoughts...",
|
| "Hmm... I need to think about this a bit more. Please give me a moment.",
|
| "My thoughts are a bit scattered. Give me a moment to organize them.",
|
| "Let me rephrase that. Just a moment please.",
|
| "Oops, I got distracted. Could you repeat that?"
|
| ];
|
|
|
| return errorResponses[Math.floor(Math.random() * errorResponses.length)];
|
| }
|
|
|
|
|
| setChatMode(mode) {
|
| if (['casual', 'assistant', 'creative'].includes(mode)) {
|
| this.currentMode = mode;
|
| console.log(`Chat mode switched to: ${mode}`);
|
| return true;
|
| }
|
| return false;
|
| }
|
|
|
|
|
| getCurrentConfig() {
|
| return {
|
| useCloudAPI: false,
|
| provider: { name: 'simple', model: 'SimpleBellaAI' },
|
| mode: this.currentMode,
|
| isConfigured: true,
|
| isInitialized: this.isInitialized
|
| };
|
| }
|
|
|
|
|
| clearHistory() {
|
| console.log('Conversation history cleared');
|
| }
|
| }
|
|
|
|
|
| window.SimpleBellaAI = SimpleBellaAI;
|
|
|
| window.BellaAI = SimpleBellaAI;
|
|
|
| console.log('SimpleBellaAI loaded successfully'); |