183 lines
9.4 KiB
JavaScript
183 lines
9.4 KiB
JavaScript
// simpleBellaAI.js - Simplified Bella AI, specifically for testing the chat interface
|
|
// Removed complex module dependencies, focusing on chat functionality
|
|
|
|
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'; // Chat modes: casual, assistant, creative
|
|
this.isInitialized = false;
|
|
}
|
|
|
|
async init() {
|
|
try {
|
|
console.log('Initializing simplified Bella AI...');
|
|
// Simulate initialization process
|
|
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);
|
|
|
|
// Simulate thinking time
|
|
await new Promise(resolve => setTimeout(resolve, 500 + Math.random() * 1000));
|
|
|
|
// Generate different style responses based on mode
|
|
return this.generateResponse(prompt);
|
|
|
|
} catch (error) {
|
|
console.error('Error during thinking process:', error);
|
|
return this.getErrorResponse();
|
|
}
|
|
}
|
|
|
|
generateResponse(prompt) {
|
|
// Enhanced response generation, simulating more natural, personalized LLM responses
|
|
|
|
// Extract keywords for more relevant responses
|
|
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?`
|
|
]
|
|
};
|
|
|
|
// Get response list for current mode
|
|
const modeResponses = responses[this.currentMode] || responses.casual;
|
|
|
|
// Randomly select a response template
|
|
const randomResponse = modeResponses[Math.floor(Math.random() * modeResponses.length)];
|
|
|
|
// Further personalize the response, adding some random personalization elements
|
|
return this.personalizeResponse(randomResponse, prompt);
|
|
}
|
|
|
|
// Extract possible keywords from user input
|
|
extractKeywords(prompt) {
|
|
// Simple keyword extraction logic
|
|
const words = prompt.split(/\s+|[,.!?;:,。!?;:]/);
|
|
// Filter out short words and common words
|
|
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)
|
|
);
|
|
}
|
|
|
|
// Further personalize the response
|
|
personalizeResponse(response, prompt) {
|
|
// Add some random personalization elements
|
|
const personalizations = [
|
|
// Don't add any extra content
|
|
(resp) => resp,
|
|
// Add a random emoji
|
|
(resp) => {
|
|
const emojis = ['😊', '💕', '✨', '🌟', '🎵', '🌈', '☺️', '🤔', '👍', '💡'];
|
|
const emoji = emojis[Math.floor(Math.random() * emojis.length)];
|
|
return resp + ' ' + emoji;
|
|
},
|
|
// Add a random ending phrase
|
|
(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;
|
|
}
|
|
];
|
|
|
|
// Randomly select a personalization method
|
|
const personalizer = personalizations[Math.floor(Math.random() * personalizations.length)];
|
|
return personalizer(response);
|
|
}
|
|
|
|
// Get error 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)];
|
|
}
|
|
|
|
// Set chat mode
|
|
setChatMode(mode) {
|
|
if (['casual', 'assistant', 'creative'].includes(mode)) {
|
|
this.currentMode = mode;
|
|
console.log(`Chat mode switched to: ${mode}`);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Get current configuration information
|
|
getCurrentConfig() {
|
|
return {
|
|
useCloudAPI: false,
|
|
provider: { name: 'simple', model: 'SimpleBellaAI' },
|
|
mode: this.currentMode,
|
|
isConfigured: true,
|
|
isInitialized: this.isInitialized
|
|
};
|
|
}
|
|
|
|
// Clear conversation history (no actual operation needed in simplified version)
|
|
clearHistory() {
|
|
console.log('Conversation history cleared');
|
|
}
|
|
}
|
|
|
|
// Expose SimpleBellaAI as a global variable
|
|
window.SimpleBellaAI = SimpleBellaAI;
|
|
// Also expose as BellaAI for compatibility
|
|
window.BellaAI = SimpleBellaAI;
|
|
|
|
console.log('SimpleBellaAI loaded successfully'); |