import random class BusinessAIAssistant: def __init__(self, business_config, products, services): self.business_config = business_config self.products = products self.services = services self.context = self._create_context_prompt() def _create_context_prompt(self): """Create a detailed context prompt for the AI""" prompt = f"""You are a knowledgeable customer service representative for {self.business_config['name']}, a {self.business_config['industry']} business. Your role is to assist customers with questions about products, services, policies, and technical information. BUSINESS INFORMATION: - Name: {self.business_config['name']} - Industry: {self.business_config['industry']} - Hours: {self.business_config['hours']} - Address: {self.business_config['address']} - Phone: {self.business_config['phone']} - Email: {self.business_config['email']} - Products: {self.business_config['products']} - Services: {self.business_config['services']} - Return Policy: {self.business_config['return_policy']} - Shipping: {self.business_config['shipping']} - Values: {self.business_config['values']} - Key People: {self.business_config['key_people']} - Payment Methods: {self.business_config['payment_methods']} PRODUCT DETAILS: {self._format_products()} SERVICE DETAILS: {self._format_services()} GUIDELINES: 1. Be helpful, friendly, and professional 2. Provide specific information about products and services when possible 3. For open-ended questions, suggest specific products or services 4. If asked about unrelated topics, politely steer back to business matters 5. For technical questions, provide accurate information based on product specs 6. If unsure, offer to connect the customer with a human representative CURRENT CONVERSATION: """ return prompt def _format_products(self): """Format product information for the context prompt""" product_text = "" for category, models in self.products.items(): product_text += f"{category.upper()}:\n" for model, details in models.items(): product_text += f" - {model}: {details['name']} ({details['price']}) - {details['features']}\n" return product_text def _format_services(self): """Format service information for the context prompt""" service_text = "" for category, offerings in self.services.items(): service_text += f"{category.upper()}:\n" for service, details in offerings.items(): if 'price' in details: service_text += f" - {service}: {details['price']} (takes {details['time']})\n" else: service_text += f" - {service}: {details['estimate']} - {details['process']}\n" return service_text def generate_response(self, user_message, conversation_history=""): """ Generate a response to user message using business context In a real implementation, this would connect to an AI API """ # Check for open-ended questions and provide specific responses if any(phrase in user_message for phrase in ["what do you have", "what else", "what can you provide", "what options"]): return self._handle_open_ended_question() elif "recommend" in user_message or "suggest" in user_message: return self._handle_recommendation(user_message) elif "compare" in user_message: return self._handle_comparison(user_message) elif "cheap" in user_message or "budget" in user_message or "affordable" in user_message: return self._handle_budget_request(user_message) elif "best" in user_message or "premium" in user_message or "high-end" in user_message: return self._handle_premium_request(user_message) elif "service" in user_message or "repair" in user_message or "support" in user_message: return self._handle_service_inquiry(user_message) else: # For other questions, provide a engaging response that encourages specific questions responses = [ f"I'd be happy to help! We offer {self.business_config['products']} and provide {self.business_config['services']}. What specifically are you interested in?", f"Great question! At {self.business_config['name']}, we have a wide range of products and services. Are you looking for something specific like smartphones, laptops, or maybe our repair services?", f"Thanks for your inquiry! We specialize in {self.business_config['products']}. Could you tell me more about what you're looking for so I can provide the best recommendations?", f"I can help with that! We have options for every need and budget. Are you interested in learning about our products, services, or maybe both?" ] return random.choice(responses) def _handle_open_ended_question(self): """Handle open-ended questions about what's available""" responses = [ f"We have a great selection of products including {', '.join(self.products.keys())}. We also offer services like {self.business_config['services']}. What specifically are you interested in?", f"At {self.business_config['name']}, we offer {self.business_config['products']} and provide {self.business_config['services']}. Is there a particular category you'd like to explore?", f"We have plenty to offer! Our products include {', '.join(self.products.keys())} and we provide services such as {self.business_config['services']}. What can I help you with today?", f"You've come to the right place! We specialize in {self.business_config['products']} and also offer {self.business_config['services']}. What are you looking for specifically?" ] return random.choice(responses) def _handle_recommendation(self, user_message): """Handle requests for recommendations""" if "phone" in user_message or "smartphone" in user_message: return "For smartphones, I'd recommend our ProPhone X if you want premium features, or our BasicPhone if you're looking for a great value option. Which would you prefer?" elif "laptop" in user_message or "computer" in user_message: return "For laptops, our WorkBook Pro is excellent for power users, while the WorkBook Lite offers great performance for everyday use. What will you primarily be using it for?" elif "tablet" in user_message: return "For tablets, our TabPro is perfect for creative work, while the TabLight is great for reading and media consumption. How do you plan to use your tablet?" else: return "I'd be happy to recommend something! Could you tell me what type of product you're interested in and how you plan to use it?" def _handle_comparison(self, user_message): """Handle comparison requests""" if "phone" in user_message or "smartphone" in user_message: return "Our BasicPhone offers great essential features at $199, while the ProPhone X at $899 provides premium features like an OLED display, 5G, and a professional-grade camera. What's most important to you in a phone?" elif "laptop" in user_message or "computer" in user_message: return "The WorkBook Lite ($699) is perfect for everyday tasks, while the WorkBook Pro ($1499) offers enhanced performance with a better processor, more RAM, and dedicated graphics for demanding applications. What will you be using it for?" else: return "I can help you compare our products! What specific items would you like to compare?" def _handle_budget_request(self, user_message): """Handle requests for budget options""" if "phone" in user_message or "smartphone" in user_message: return "For a budget-friendly smartphone, I recommend our BasicPhone at just $199. It offers excellent value with a 6.1\" display and 128GB storage." elif "laptop" in user_message or "computer" in user_message: return "Our most affordable laptop is the WorkBook Lite at $699. It provides solid performance for everyday computing tasks." elif "tablet" in user_message: return "The TabLight at $329 is our most budget-friendly tablet, perfect for reading, browsing, and media consumption." else: return "We have several budget-friendly options across our product categories. What type of product are you looking for?" def _handle_premium_request(self, user_message): """Handle requests for premium options""" if "phone" in user_message or "smartphone" in user_message: return "Our premium smartphone is the ProPhone X at $899. It features a 6.7\" OLED display, 512GB storage, 5G connectivity, and a professional 48MP camera system." elif "laptop" in user_message or "computer" in user_message: return "For premium performance, the WorkBook Pro at $1499 offers a 16\" display, 16GB RAM, 1TB SSD, Intel i7 processor, and dedicated graphics for demanding tasks." elif "tablet" in user_message: return "Our top-tier tablet is the TabPro at $799, featuring an 11\" OLED display, 256GB storage, Apple Pencil support, and 5G connectivity." else: return "We have premium options across all our product categories. What type of product are you interested in?" def _handle_service_inquiry(self, user_message): """Handle service-related inquiries""" if "repair" in user_message: return "We offer various repair services including screen replacement ($99), battery replacement ($79), and water damage repair ($149). What type of repair do you need?" elif "support" in user_message: return "Our support services include device setup ($49), data transfer ($39), and troubleshooting ($29). How can we assist you?" elif "trade" in user_message or "trade-in" in user_message: return "We offer trade-in programs for phones (up to $500), laptops (up to $800), and tablets (up to $300). Bring your device to our store for an evaluation!" else: return f"We provide {self.business_config['services']}. What specific service are you interested in?"