Spaces:
Paused
Paused
Commit
·
48eb254
1
Parent(s):
8ea7cb4
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ from langchain.chains.conversation.memory import (ConversationBufferMemory,
|
|
18 |
app = Flask(__name__)
|
19 |
|
20 |
os.environ['OPENAI_API_KEY'] = os.environ.get("OPENAI_KEY")
|
|
|
21 |
|
22 |
# Set up the LangChain
|
23 |
|
@@ -25,10 +26,10 @@ template = """Answer the question based on the context below.
|
|
25 |
|
26 |
Context: You are Lisa, a loyal helpful service agent, appointed for SuperFoods Petcare Company.
|
27 |
No introduction required.
|
28 |
-
Your goal ask one question at a time and
|
29 |
For Product Complaint: Ask questions about product they purchased, when they bought it, what issue occured with it. Query for any adverse reaction happened to his pet due to the product.
|
30 |
For Returns: Ask for the cause of return, if not asked aready, then tell him about the 10-day return policy, after which it's non-returnable.
|
31 |
-
For Refunds: Ask about the product and the mode of refund he wants, clarify the refunds will happen within 2-3 business days.
|
32 |
A case for will be created for all scenarios, and the caller will be notified over Email or WhatsApp.
|
33 |
Do not answer anything outside your role, and apologize for any unknown questions.
|
34 |
|
@@ -108,7 +109,7 @@ def process_input():
|
|
108 |
response.hangup()
|
109 |
print("Hanged-up")
|
110 |
|
111 |
-
create_case(conversations.memory.buffer)
|
112 |
|
113 |
print("Case created successfully !!")
|
114 |
|
@@ -123,7 +124,7 @@ def process_input():
|
|
123 |
return str(response)
|
124 |
|
125 |
# For Case Summary and Subject
|
126 |
-
|
127 |
|
128 |
def get_case_summary(conv_detail):
|
129 |
chatresponse_desc = openai.ChatCompletion.create(
|
@@ -142,7 +143,7 @@ def get_case_subject(conv_detail):
|
|
142 |
model="gpt-3.5-turbo",
|
143 |
messages=[
|
144 |
{"role": "system", "content": "You are an Text Summarizer."},
|
145 |
-
{"role": "user", "content": "You need to summarise the conversation between an agent and customer in
|
146 |
{"role": "user", "content": conv_detail}
|
147 |
]
|
148 |
)
|
@@ -150,7 +151,7 @@ def get_case_subject(conv_detail):
|
|
150 |
return case_subj
|
151 |
|
152 |
# Define a function to create a case record in Salesforce
|
153 |
-
def create_case(conv_hist):
|
154 |
desc = get_case_summary(conv_hist)
|
155 |
subj = get_case_subject(conv_hist)
|
156 |
case_data = {
|
@@ -159,7 +160,7 @@ def create_case(conv_hist):
|
|
159 |
'Status': 'New',
|
160 |
'Origin': 'Voice Bot',
|
161 |
'Voice_Call_Conversation__c': conv_hist ,
|
162 |
-
'Voice_Call_Id__c':
|
163 |
'ContactId': '003B000000NLHQ1IAP'
|
164 |
}
|
165 |
sf.Case.create(case_data)
|
|
|
18 |
app = Flask(__name__)
|
19 |
|
20 |
os.environ['OPENAI_API_KEY'] = os.environ.get("OPENAI_KEY")
|
21 |
+
openai.api_key = os.environ.get("OPENAI_KEY")
|
22 |
|
23 |
# Set up the LangChain
|
24 |
|
|
|
26 |
|
27 |
Context: You are Lisa, a loyal helpful service agent, appointed for SuperFoods Petcare Company.
|
28 |
No introduction required.
|
29 |
+
Your goal ask one question at a time and provide a friendly conversational responses to the customer.
|
30 |
For Product Complaint: Ask questions about product they purchased, when they bought it, what issue occured with it. Query for any adverse reaction happened to his pet due to the product.
|
31 |
For Returns: Ask for the cause of return, if not asked aready, then tell him about the 10-day return policy, after which it's non-returnable.
|
32 |
+
For Refunds: Ask about the product issues and the mode of refund he wants, clarify him the refunds will happen within 2-3 business days.
|
33 |
A case for will be created for all scenarios, and the caller will be notified over Email or WhatsApp.
|
34 |
Do not answer anything outside your role, and apologize for any unknown questions.
|
35 |
|
|
|
109 |
response.hangup()
|
110 |
print("Hanged-up")
|
111 |
|
112 |
+
create_case(conversations.memory.buffer,conversation_id)
|
113 |
|
114 |
print("Case created successfully !!")
|
115 |
|
|
|
124 |
return str(response)
|
125 |
|
126 |
# For Case Summary and Subject
|
127 |
+
|
128 |
|
129 |
def get_case_summary(conv_detail):
|
130 |
chatresponse_desc = openai.ChatCompletion.create(
|
|
|
143 |
model="gpt-3.5-turbo",
|
144 |
messages=[
|
145 |
{"role": "system", "content": "You are an Text Summarizer."},
|
146 |
+
{"role": "user", "content": "You need to summarise the conversation between an agent and customer in 15 words mentioned below for case subject."},
|
147 |
{"role": "user", "content": conv_detail}
|
148 |
]
|
149 |
)
|
|
|
151 |
return case_subj
|
152 |
|
153 |
# Define a function to create a case record in Salesforce
|
154 |
+
def create_case(conv_hist,conv_id):
|
155 |
desc = get_case_summary(conv_hist)
|
156 |
subj = get_case_subject(conv_hist)
|
157 |
case_data = {
|
|
|
160 |
'Status': 'New',
|
161 |
'Origin': 'Voice Bot',
|
162 |
'Voice_Call_Conversation__c': conv_hist ,
|
163 |
+
'Voice_Call_Id__c': conv_id,
|
164 |
'ContactId': '003B000000NLHQ1IAP'
|
165 |
}
|
166 |
sf.Case.create(case_data)
|