Spaces:
Sleeping
Sleeping
modified custom question
Browse files
app.py
CHANGED
|
@@ -147,7 +147,7 @@ def qa_automation(text: str):
|
|
| 147 |
# "Did the agent get a promise to pay? Provide Details."
|
| 148 |
"Rate the satisfaction of the customer on a scale of 10. 0 being worse and 10 being best.",
|
| 149 |
#"Rate the customer effort on a scale of 0-10. 0 being the most effort spent by the customer and 10 being least effort:",
|
| 150 |
-
"How could the agent have made the call easier for the customer?"
|
| 151 |
]
|
| 152 |
answers = []
|
| 153 |
for question in questions:
|
|
@@ -157,7 +157,8 @@ def qa_automation(text: str):
|
|
| 157 |
{"role": "system", "content": "You are an AI assistant evaluating a customer service call based on quality assurance criteria."},
|
| 158 |
{"role": "user", "content": f"Question: {question}\nTranscript: {text}\nAnswer:"}
|
| 159 |
],
|
| 160 |
-
max_tokens=
|
|
|
|
| 161 |
)
|
| 162 |
if response.choices:
|
| 163 |
answer = response.choices[0].message.content.strip()
|
|
@@ -275,35 +276,71 @@ def check_agent_steps(text: str):
|
|
| 275 |
|
| 276 |
return GenerateResponse4(text=results)
|
| 277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
def custom_qa_automation(text: str, custom_question: str):
|
| 279 |
# Ensure the custom question ends with "Provide Details."
|
| 280 |
if not custom_question.strip().endswith("Provide Details."):
|
| 281 |
custom_question = custom_question.strip() + " Provide Details."
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
#return GenerateResponse(text=formatted_answer)
|
| 309 |
return formatted_answer # Returning string directly instead of being placed within the GenerateResponse class
|
|
|
|
| 147 |
# "Did the agent get a promise to pay? Provide Details."
|
| 148 |
"Rate the satisfaction of the customer on a scale of 10. 0 being worse and 10 being best.",
|
| 149 |
#"Rate the customer effort on a scale of 0-10. 0 being the most effort spent by the customer and 10 being least effort:",
|
| 150 |
+
"How could the agent have made the call easier for the customer in 3 simple steps?"
|
| 151 |
]
|
| 152 |
answers = []
|
| 153 |
for question in questions:
|
|
|
|
| 157 |
{"role": "system", "content": "You are an AI assistant evaluating a customer service call based on quality assurance criteria."},
|
| 158 |
{"role": "user", "content": f"Question: {question}\nTranscript: {text}\nAnswer:"}
|
| 159 |
],
|
| 160 |
+
max_tokens=250,
|
| 161 |
+
temperature=0.5
|
| 162 |
)
|
| 163 |
if response.choices:
|
| 164 |
answer = response.choices[0].message.content.strip()
|
|
|
|
| 276 |
|
| 277 |
return GenerateResponse4(text=results)
|
| 278 |
|
| 279 |
+
# def custom_qa_automation(text: str, custom_question: str):
|
| 280 |
+
# # Ensure the custom question ends with "Provide Details."
|
| 281 |
+
# if not custom_question.strip().endswith("Provide Details."):
|
| 282 |
+
# custom_question = custom_question.strip() + " Provide Details."
|
| 283 |
+
|
| 284 |
+
# response = openai.Completion.create(
|
| 285 |
+
# engine="AmplifAI-Chat",
|
| 286 |
+
# prompt=f"Respons with a Yes/No followed by a reason. Question: {custom_question}\nTranscript: {text}\nAnswer:",
|
| 287 |
+
# temperature=0.2,
|
| 288 |
+
# max_tokens=100,
|
| 289 |
+
# top_p=1.0,
|
| 290 |
+
# frequency_penalty=0.0,
|
| 291 |
+
# presence_penalty=0.0,
|
| 292 |
+
# stop=["\n"]
|
| 293 |
+
# )
|
| 294 |
+
# answer = response.choices[0].text.strip()
|
| 295 |
+
# # Split the answer into the main answer (Yes/No) and the details
|
| 296 |
+
# if "Yes" in answer:
|
| 297 |
+
# main_answer, details = answer.split("Yes", 1)
|
| 298 |
+
# main_answer += "Yes"
|
| 299 |
+
# elif "No" in answer:
|
| 300 |
+
# main_answer, details = answer.split("No", 1)
|
| 301 |
+
# main_answer += "No"
|
| 302 |
+
# else:
|
| 303 |
+
# main_answer = answer
|
| 304 |
+
# details = "No additional details provided."
|
| 305 |
+
|
| 306 |
+
# # Format the answer with the "Comments:" tag in bold and on a new line
|
| 307 |
+
# formatted_answer = f"<p><b>Response:</b> {main_answer}</p><p><b>Comment:</b> {details}</p>" #f"**{custom_question}** {main_answer}\n\n**Comments:** {details}"
|
| 308 |
+
|
| 309 |
+
# #return GenerateResponse(text=formatted_answer)
|
| 310 |
+
# return formatted_answer # Returning string directly instead of being placed within the GenerateResponse class
|
| 311 |
+
|
| 312 |
def custom_qa_automation(text: str, custom_question: str):
|
| 313 |
# Ensure the custom question ends with "Provide Details."
|
| 314 |
if not custom_question.strip().endswith("Provide Details."):
|
| 315 |
custom_question = custom_question.strip() + " Provide Details."
|
| 316 |
|
| 317 |
+
response = client.chat.completions.create(
|
| 318 |
+
model = deployment_name,
|
| 319 |
+
messages=[
|
| 320 |
+
{"role": "system", "content": "You are an AI assistant evaluating a customer service call. Keep responses concise."},
|
| 321 |
+
{"role": "user", "content": f"Question: {custom_question}\nTranscript: {text}\nAnswer with a brief Yes/No and a short reason (max 1 sentence):"}
|
| 322 |
+
],
|
| 323 |
+
temperature=0.2,
|
| 324 |
+
max_tokens=100,
|
| 325 |
+
top_p=1.0,
|
| 326 |
+
frequency_penalty=0.0,
|
| 327 |
+
presence_penalty=0.0,
|
| 328 |
+
stop=["\n"]
|
| 329 |
+
)
|
| 330 |
+
answer = response.choices[0].message.content.strip()
|
| 331 |
+
# Split the answer into the main answer (Yes/No) and the details
|
| 332 |
+
if "Yes" in answer:
|
| 333 |
+
main_answer, details = answer.split("Yes", 1)
|
| 334 |
+
main_answer += "Yes"
|
| 335 |
+
elif "No" in answer:
|
| 336 |
+
main_answer, details = answer.split("No", 1)
|
| 337 |
+
main_answer += "No"
|
| 338 |
+
else:
|
| 339 |
+
main_answer = answer
|
| 340 |
+
details = "No additional details provided."
|
| 341 |
+
|
| 342 |
+
# Format the answer with the "Comments:" tag in bold and on a new line
|
| 343 |
+
formatted_answer = f"<p><b>Response:</b> {main_answer}</p><p><b>Comment:</b> {details}</p>" #f"**{custom_question}** {main_answer}\n\n**Comments:** {details}"
|
| 344 |
|
| 345 |
#return GenerateResponse(text=formatted_answer)
|
| 346 |
return formatted_answer # Returning string directly instead of being placed within the GenerateResponse class
|