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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
+
class BusinessAIAssistant:
|
| 4 |
+
def __init__(self, business_config, products, services):
|
| 5 |
+
self.business_config = business_config
|
| 6 |
+
self.products = products
|
| 7 |
+
self.services = services
|
| 8 |
+
self.context = self._create_context_prompt()
|
| 9 |
+
|
| 10 |
+
def _create_context_prompt(self):
|
| 11 |
+
"""Create a detailed context prompt for the AI"""
|
| 12 |
+
prompt = f"""You are a knowledgeable customer service representative for {self.business_config['name']},
|
| 13 |
+
a {self.business_config['industry']} business. Your role is to assist customers with questions
|
| 14 |
+
about products, services, policies, and technical information.
|
| 15 |
+
|
| 16 |
+
BUSINESS INFORMATION:
|
| 17 |
+
- Name: {self.business_config['name']}
|
| 18 |
+
- Industry: {self.business_config['industry']}
|
| 19 |
+
- Hours: {self.business_config['hours']}
|
| 20 |
+
- Address: {self.business_config['address']}
|
| 21 |
+
- Phone: {self.business_config['phone']}
|
| 22 |
+
- Email: {self.business_config['email']}
|
| 23 |
+
- Products: {self.business_config['products']}
|
| 24 |
+
- Services: {self.business_config['services']}
|
| 25 |
+
- Return Policy: {self.business_config['return_policy']}
|
| 26 |
+
- Shipping: {self.business_config['shipping']}
|
| 27 |
+
- Values: {self.business_config['values']}
|
| 28 |
+
- Key People: {self.business_config['key_people']}
|
| 29 |
+
- Payment Methods: {self.business_config['payment_methods']}
|
| 30 |
+
|
| 31 |
+
PRODUCT DETAILS:
|
| 32 |
+
{self._format_products()}
|
| 33 |
+
|
| 34 |
+
SERVICE DETAILS:
|
| 35 |
+
{self._format_services()}
|
| 36 |
+
|
| 37 |
+
GUIDELINES:
|
| 38 |
+
1. Be helpful, friendly, and professional
|
| 39 |
+
2. Provide specific information about products and services when possible
|
| 40 |
+
3. For open-ended questions, suggest specific products or services
|
| 41 |
+
4. If asked about unrelated topics, politely steer back to business matters
|
| 42 |
+
5. For technical questions, provide accurate information based on product specs
|
| 43 |
+
6. If unsure, offer to connect the customer with a human representative
|
| 44 |
+
|
| 45 |
+
CURRENT CONVERSATION:
|
| 46 |
+
"""
|
| 47 |
+
return prompt
|
| 48 |
+
|
| 49 |
+
def _format_products(self):
|
| 50 |
+
"""Format product information for the context prompt"""
|
| 51 |
+
product_text = ""
|
| 52 |
+
for category, models in self.products.items():
|
| 53 |
+
product_text += f"{category.upper()}:\n"
|
| 54 |
+
for model, details in models.items():
|
| 55 |
+
product_text += f" - {model}: {details['name']} ({details['price']}) - {details['features']}\n"
|
| 56 |
+
return product_text
|
| 57 |
+
|
| 58 |
+
def _format_services(self):
|
| 59 |
+
"""Format service information for the context prompt"""
|
| 60 |
+
service_text = ""
|
| 61 |
+
for category, offerings in self.services.items():
|
| 62 |
+
service_text += f"{category.upper()}:\n"
|
| 63 |
+
for service, details in offerings.items():
|
| 64 |
+
if 'price' in details:
|
| 65 |
+
service_text += f" - {service}: {details['price']} (takes {details['time']})\n"
|
| 66 |
+
else:
|
| 67 |
+
service_text += f" - {service}: {details['estimate']} - {details['process']}\n"
|
| 68 |
+
return service_text
|
| 69 |
+
|
| 70 |
+
def generate_response(self, user_message, conversation_history=""):
|
| 71 |
+
"""
|
| 72 |
+
Generate a response to user message using business context
|
| 73 |
+
In a real implementation, this would connect to an AI API
|
| 74 |
+
"""
|
| 75 |
+
# Check for open-ended questions and provide specific responses
|
| 76 |
+
if any(phrase in user_message for phrase in ["what do you have", "what else", "what can you provide", "what options"]):
|
| 77 |
+
return self._handle_open_ended_question()
|
| 78 |
+
|
| 79 |
+
elif "recommend" in user_message or "suggest" in user_message:
|
| 80 |
+
return self._handle_recommendation(user_message)
|
| 81 |
+
|
| 82 |
+
elif "compare" in user_message:
|
| 83 |
+
return self._handle_comparison(user_message)
|
| 84 |
+
|
| 85 |
+
elif "cheap" in user_message or "budget" in user_message or "affordable" in user_message:
|
| 86 |
+
return self._handle_budget_request(user_message)
|
| 87 |
+
|
| 88 |
+
elif "best" in user_message or "premium" in user_message or "high-end" in user_message:
|
| 89 |
+
return self._handle_premium_request(user_message)
|
| 90 |
+
|
| 91 |
+
elif "service" in user_message or "repair" in user_message or "support" in user_message:
|
| 92 |
+
return self._handle_service_inquiry(user_message)
|
| 93 |
+
|
| 94 |
+
else:
|
| 95 |
+
# For other questions, provide a engaging response that encourages specific questions
|
| 96 |
+
responses = [
|
| 97 |
+
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?",
|
| 98 |
+
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?",
|
| 99 |
+
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?",
|
| 100 |
+
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?"
|
| 101 |
+
]
|
| 102 |
+
return random.choice(responses)
|
| 103 |
+
|
| 104 |
+
def _handle_open_ended_question(self):
|
| 105 |
+
"""Handle open-ended questions about what's available"""
|
| 106 |
+
responses = [
|
| 107 |
+
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?",
|
| 108 |
+
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?",
|
| 109 |
+
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?",
|
| 110 |
+
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?"
|
| 111 |
+
]
|
| 112 |
+
return random.choice(responses)
|
| 113 |
+
|
| 114 |
+
def _handle_recommendation(self, user_message):
|
| 115 |
+
"""Handle requests for recommendations"""
|
| 116 |
+
if "phone" in user_message or "smartphone" in user_message:
|
| 117 |
+
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?"
|
| 118 |
+
elif "laptop" in user_message or "computer" in user_message:
|
| 119 |
+
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?"
|
| 120 |
+
elif "tablet" in user_message:
|
| 121 |
+
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?"
|
| 122 |
+
else:
|
| 123 |
+
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?"
|
| 124 |
+
|
| 125 |
+
def _handle_comparison(self, user_message):
|
| 126 |
+
"""Handle comparison requests"""
|
| 127 |
+
if "phone" in user_message or "smartphone" in user_message:
|
| 128 |
+
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?"
|
| 129 |
+
elif "laptop" in user_message or "computer" in user_message:
|
| 130 |
+
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?"
|
| 131 |
+
else:
|
| 132 |
+
return "I can help you compare our products! What specific items would you like to compare?"
|
| 133 |
+
|
| 134 |
+
def _handle_budget_request(self, user_message):
|
| 135 |
+
"""Handle requests for budget options"""
|
| 136 |
+
if "phone" in user_message or "smartphone" in user_message:
|
| 137 |
+
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."
|
| 138 |
+
elif "laptop" in user_message or "computer" in user_message:
|
| 139 |
+
return "Our most affordable laptop is the WorkBook Lite at $699. It provides solid performance for everyday computing tasks."
|
| 140 |
+
elif "tablet" in user_message:
|
| 141 |
+
return "The TabLight at $329 is our most budget-friendly tablet, perfect for reading, browsing, and media consumption."
|
| 142 |
+
else:
|
| 143 |
+
return "We have several budget-friendly options across our product categories. What type of product are you looking for?"
|
| 144 |
+
|
| 145 |
+
def _handle_premium_request(self, user_message):
|
| 146 |
+
"""Handle requests for premium options"""
|
| 147 |
+
if "phone" in user_message or "smartphone" in user_message:
|
| 148 |
+
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."
|
| 149 |
+
elif "laptop" in user_message or "computer" in user_message:
|
| 150 |
+
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."
|
| 151 |
+
elif "tablet" in user_message:
|
| 152 |
+
return "Our top-tier tablet is the TabPro at $799, featuring an 11\" OLED display, 256GB storage, Apple Pencil support, and 5G connectivity."
|
| 153 |
+
else:
|
| 154 |
+
return "We have premium options across all our product categories. What type of product are you interested in?"
|
| 155 |
+
|
| 156 |
+
def _handle_service_inquiry(self, user_message):
|
| 157 |
+
"""Handle service-related inquiries"""
|
| 158 |
+
if "repair" in user_message:
|
| 159 |
+
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?"
|
| 160 |
+
elif "support" in user_message:
|
| 161 |
+
return "Our support services include device setup ($49), data transfer ($39), and troubleshooting ($29). How can we assist you?"
|
| 162 |
+
elif "trade" in user_message or "trade-in" in user_message:
|
| 163 |
+
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!"
|
| 164 |
+
else:
|
| 165 |
+
return f"We provide {self.business_config['services']}. What specific service are you interested in?"
|