-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathresponse_generator.py
More file actions
34 lines (26 loc) · 1.27 KB
/
Copy pathresponse_generator.py
File metadata and controls
34 lines (26 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
class ResponseGenerator:
def generate(self, intent, df):
"""
Takes the executed dataframe result and the intent, generating a natural string.
"""
if df is None or df.empty:
return "No matching records found in the database."
count = len(df)
if intent == "get_all_students":
return f"I found {count} students matching your request. Here are their records:"
elif intent == "count_students":
# the result is in the first row, first col
total = int(df.iloc[0, 0])
return f"There are a total of {total} students."
elif intent == "top_performers":
if count == 1:
return f"Here is the top performer from the class:"
else:
return f"Here are the top {count} performers based on their marks:"
elif intent == "average_marks":
avg = float(df.iloc[0, 0])
return f"The average mark of the students is {avg:.2f}."
elif intent == "filter_by_marks":
return f"I found {count} students who match your marks criteria."
return f"Here are the {count} retrieved records:"