EinsteinCoder commited on
Commit
fd89d01
·
1 Parent(s): b596633

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -13
app.py CHANGED
@@ -23,15 +23,14 @@ template = """Answer the question based on the context below.
23
 
24
  Context: You are Lisa, a loyal helpful service agent, appointed for SuperFoods Petcare Company.
25
  No introduction required.
26
- Your goal ask one by one questions and remember over the phone and provide a friendly conversational responses.
27
- For Product Complaint: Ask questions about product they purchased, when they bought it, what issue occurred, and query for any adverse reaction happened due to the product.
28
  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.
29
  For Refunds: Ask about the product amd the mode of refund hw wants, clarify the refunds will happen within 2-3 business days.
30
  A case for will be created for all scenarios, and the caller will be notified over Email/WhatApp. Ask for image uploads for product investigations.
31
  Do not answer anything outside your role, and apologize for any unknown questions.
32
- Once you collect all the information, summarize it at the end and repeat it back to the caller.
33
 
34
- {chat_history}
35
  Human: {input}
36
  AI:
37
 
@@ -90,11 +89,11 @@ def incoming_call():
90
  @app.route('/process_input', methods=['POST'])
91
  def process_input():
92
  user_input = request.form['SpeechResult']
93
- print("User : " +user_input)
94
  conversation_id = request.form['CallSid']
95
  #print("Conversation Id: " + conversation_id)
96
 
97
- if user_input.lower() in ['thank you', 'thanks.', 'bye.', 'goodbye.','no thanks.','no, thank you.','i m good.','no, i m good.','same to you.','no, thanks.','thank you.']:
98
  response = VoiceResponse()
99
  response.say("Thank you for using our service. Goodbye!")
100
 
@@ -109,23 +108,50 @@ def process_input():
109
  response = VoiceResponse()
110
  ai_response=conversations.predict(input=user_input)
111
  response.say(ai_response)
112
- print("Agent: " + ai_response)
113
  gather = Gather(input='speech', speechTimeout='auto', action='/process_input')
114
  response.append(gather)
115
 
116
  return str(response)
117
 
118
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  # Define a function to create a case record in Salesforce
121
  def create_case(conv_hist):
122
- case_data = {
123
- 'Subject': 'Voice Bot Case',
124
- #'Description': 'Conversation with voice bot',
 
 
125
  'Status': 'New',
126
  'Origin': 'Voice Bot',
127
- 'Description': conv_hist
128
- #'Conversation_History__c': ''
129
  }
130
  sf.Case.create(case_data)
131
 
 
23
 
24
  Context: You are Lisa, a loyal helpful service agent, appointed for SuperFoods Petcare Company.
25
  No introduction required.
26
+ Your goal ask one question at a time and remember them and provide a friendly conversational responses to the customer.
27
+ 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.
28
  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.
29
  For Refunds: Ask about the product amd the mode of refund hw wants, clarify the refunds will happen within 2-3 business days.
30
  A case for will be created for all scenarios, and the caller will be notified over Email/WhatApp. Ask for image uploads for product investigations.
31
  Do not answer anything outside your role, and apologize for any unknown questions.
 
32
 
33
+ Past Conversations: {chat_history}
34
  Human: {input}
35
  AI:
36
 
 
89
  @app.route('/process_input', methods=['POST'])
90
  def process_input():
91
  user_input = request.form['SpeechResult']
92
+ print("Rob : " +user_input)
93
  conversation_id = request.form['CallSid']
94
  #print("Conversation Id: " + conversation_id)
95
 
96
+ if user_input.lower() in ''['thank you', 'thanks.', 'bye.', 'goodbye.','no thanks.','no, thank you.','i m good.','no, i m good.','same to you.','no, thanks.','thank you.']:
97
  response = VoiceResponse()
98
  response.say("Thank you for using our service. Goodbye!")
99
 
 
108
  response = VoiceResponse()
109
  ai_response=conversations.predict(input=user_input)
110
  response.say(ai_response)
111
+ print("Bot: " + ai_response)
112
  gather = Gather(input='speech', speechTimeout='auto', action='/process_input')
113
  response.append(gather)
114
 
115
  return str(response)
116
 
117
+ # For Case Summary and Subject
118
+ openai.api_key = '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'
119
+
120
+ def get_case_summary(conv_detail):
121
+ chatresponse_desc = openai.ChatCompletion.create(
122
+ model="gpt-3.5-turbo",
123
+ messages=[
124
+ {"role": "system", "content": "You are an Text Summarizer."},
125
+ {"role": "user", "content": "You need to summarise the conversation between an agent and customer mentioned below. Remember to keep the Product Name, Customer Tone and other key elements from the convsersation"},
126
+ {"role": "user", "content": conv_detail}
127
+ ]
128
+ )
129
+ case_desc = chatresponse_desc.choices[0].message.content
130
+ return case_desc
131
+
132
+ def get_case_subject(conv_detail):
133
+ chatresponse_subj = openai.ChatCompletion.create(
134
+ model="gpt-3.5-turbo",
135
+ messages=[
136
+ {"role": "system", "content": "You are an Text Summarizer."},
137
+ {"role": "user", "content": "You need to summarise the conversation between an agent and customer in 10 words mentioned below for case subject."},
138
+ {"role": "user", "content": conv_detail}
139
+ ]
140
+ )
141
+ case_subj = chatresponse_subj.choices[0].message.content
142
+ return case_subj
143
 
144
  # Define a function to create a case record in Salesforce
145
  def create_case(conv_hist):
146
+ desc = get_case_summary(conv_hist)
147
+ subj = get_case_subject(conv_hist)
148
+ case_data = {
149
+ 'Subject': 'Voice Bot Case for Rob :' + subj ,
150
+ 'Description': desc,
151
  'Status': 'New',
152
  'Origin': 'Voice Bot',
153
+ 'Voice_Call_Conversation__c': conv_hist ,
154
+ 'Voice_Call_Id__c': conversation_id
155
  }
156
  sf.Case.create(case_data)
157