Spaces:
Sleeping
Sleeping
updated def qa_automation
Browse files
app.py
CHANGED
|
@@ -151,38 +151,37 @@ def qa_automation(text: str):
|
|
| 151 |
]
|
| 152 |
answers = []
|
| 153 |
for question in questions:
|
| 154 |
-
response =
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
frequency_penalty=0.0,
|
| 161 |
-
presence_penalty=0.0,
|
| 162 |
-
stop=["\n"]
|
| 163 |
)
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
| 186 |
return GenerateResponse3(text=answers)
|
| 187 |
|
| 188 |
|
|
|
|
| 151 |
]
|
| 152 |
answers = []
|
| 153 |
for question in questions:
|
| 154 |
+
response = client.chat.completions.create(
|
| 155 |
+
model = deployment_name,
|
| 156 |
+
messages=[
|
| 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 |
)
|
| 161 |
+
if response.choices:
|
| 162 |
+
answer = response.choices[0].message.content.strip()
|
| 163 |
+
|
| 164 |
+
# Split the answer into the main answer (Yes/No) and the details
|
| 165 |
+
if "Yes" in answer:
|
| 166 |
+
main_answer, details = answer.split("Yes", 1)
|
| 167 |
+
main_answer += "Yes"
|
| 168 |
+
elif "No" in answer:
|
| 169 |
+
main_answer, details = answer.split("No", 1)
|
| 170 |
+
main_answer += "No"
|
| 171 |
+
else:
|
| 172 |
+
main_answer = answer
|
| 173 |
+
details = "No additional details provided."
|
| 174 |
+
|
| 175 |
+
# Format the answer with the "Comments:" tag in bold and on a new line
|
| 176 |
+
# formatted_answer = f"**{question}** {main_answer}\n\n**Comments:** {details}" - change made on 8/27/2024
|
| 177 |
+
# Change is to attain answers as a list of dictionaries (json) instead of a formatted string
|
| 178 |
+
answer_dict = {
|
| 179 |
+
"question": question,
|
| 180 |
+
"answer": main_answer.strip(),
|
| 181 |
+
"comments": details.strip()
|
| 182 |
+
}
|
| 183 |
+
answers.append(answer_dict) # Previously, we appended formatted_answer to 'answers'
|
| 184 |
+
# return GenerateResponse(text = ("\n\n".join(answers)))
|
| 185 |
return GenerateResponse3(text=answers)
|
| 186 |
|
| 187 |
|