AmpParth commited on
Commit
29e8d29
·
verified ·
1 Parent(s): 2392be5

updated def qa_automation

Browse files
Files changed (1) hide show
  1. app.py +30 -31
app.py CHANGED
@@ -151,38 +151,37 @@ def qa_automation(text: str):
151
  ]
152
  answers = []
153
  for question in questions:
154
- response = openai.Completion.create(
155
- engine="AmplifAI-Chat",
156
- prompt=f"Question: {question}\nTranscript: {text}\nAnswer:",
157
- temperature=0.2,
158
- max_tokens=100,
159
- top_p=1.0,
160
- frequency_penalty=0.0,
161
- presence_penalty=0.0,
162
- stop=["\n"]
163
  )
164
- answer = response.choices[0].text.strip()
165
- # Split the answer into the main answer (Yes/No) and the details
166
- if "Yes" in answer:
167
- main_answer, details = answer.split("Yes", 1)
168
- main_answer += "Yes"
169
- elif "No" in answer:
170
- main_answer, details = answer.split("No", 1)
171
- main_answer += "No"
172
- else:
173
- main_answer = answer
174
- details = "No additional details provided."
175
-
176
- # Format the answer with the "Comments:" tag in bold and on a new line
177
- # formatted_answer = f"**{question}** {main_answer}\n\n**Comments:** {details}" - change made on 8/27/2024
178
- # Change is to attain answers as a list of dictionaries (json) instead of a formatted string
179
- answer_dict = {
180
- "question": question,
181
- "answer": main_answer.strip(),
182
- "comments": details.strip()
183
- }
184
- answers.append(answer_dict) # Previously, we appended formatted_answer to 'answers'
185
- # return GenerateResponse(text = ("\n\n".join(answers)))
 
 
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