-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiSalesScriptAIchatbot.py
75 lines (64 loc) · 2.38 KB
/
multiSalesScriptAIchatbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import random
from transformers import pipeline
# Initialize the NLP model for response generation
nlp = pipeline("conversational", model="microsoft/DialoGPT-large")
# Sample sales script flows
sales_flows = {
"greeting": [
"Hi there! How can I assist you today?",
"Hello! What brings you here today?"
],
"product_info": [
"We have a variety of products. Can you specify what you're interested in?",
"Are you looking for something specific?"
],
"closing": [
"Would you like to proceed with your purchase?",
"Can I help you with the checkout process?"
]
}
# Predefined responses for scoring
predefined_responses = {
"yes": ["yes", "sure", "absolutely", "definitely"],
"no": ["no", "not really", "no thanks"],
"help": ["help", "assistance", "support"]
}
# Scoring function
def score_response(user_input, expected_responses):
score = 0
for response in expected_responses:
if response in user_input.lower():
score += 1
return score
# Main chatbot function
def chatbot_flow():
flow = "greeting"
print(random.choice(sales_flows[flow]))
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit"]:
print("Chatbot: Thank you for chatting! Goodbye!")
break
if flow == "greeting":
flow = "product_info"
print(random.choice(sales_flows[flow]))
elif flow == "product_info":
score = score_response(user_input, predefined_responses["help"])
if score > 0:
print("Chatbot: Sure! I'm here to help. What do you need assistance with?")
else:
flow = "closing"
print(random.choice(sales_flows[flow]))
elif flow == "closing":
score = score_response(user_input, predefined_responses["yes"])
if score > 0:
print("Chatbot: Great! Let's proceed with your purchase.")
break
else:
score = score_response(user_input, predefined_responses["no"])
if score > 0:
print("Chatbot: No problem! Let me know if you need anything else.")
break
# Entry point for the chatbot
if __name__ == "__main__":
chatbot_flow()