Update app.py
Browse files
app.py
CHANGED
|
@@ -30,7 +30,6 @@ def analyze_attrition_with_llm(df_dict, hr_query):
|
|
| 30 |
df = df_dict["df"]
|
| 31 |
employees_data = {row["Employee"].strip(): row["Sentiment"] for _, row in df.iterrows()}
|
| 32 |
|
| 33 |
-
# Use GPT-4-turbo to analyze the HR query
|
| 34 |
response = client.chat.completions.create(
|
| 35 |
model="gpt-4-turbo",
|
| 36 |
messages=[
|
|
@@ -44,10 +43,9 @@ def analyze_attrition_with_llm(df_dict, hr_query):
|
|
| 44 |
"parameters": {
|
| 45 |
"type": "object",
|
| 46 |
"properties": {
|
| 47 |
-
"
|
| 48 |
-
"sentiment": {"type": "string", "description": "Extracted sentiment"}
|
| 49 |
},
|
| 50 |
-
"required": ["
|
| 51 |
}
|
| 52 |
}
|
| 53 |
],
|
|
@@ -58,13 +56,17 @@ def analyze_attrition_with_llm(df_dict, hr_query):
|
|
| 58 |
if hasattr(message, "function_call") and message.function_call is not None:
|
| 59 |
try:
|
| 60 |
function_call = json.loads(message.function_call.arguments)
|
| 61 |
-
|
| 62 |
-
sentiment = employees_data.get(employee_name)
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
return f"❌ Error processing LLM function call: {str(e)}"
|
| 70 |
|
|
|
|
| 30 |
df = df_dict["df"]
|
| 31 |
employees_data = {row["Employee"].strip(): row["Sentiment"] for _, row in df.iterrows()}
|
| 32 |
|
|
|
|
| 33 |
response = client.chat.completions.create(
|
| 34 |
model="gpt-4-turbo",
|
| 35 |
messages=[
|
|
|
|
| 43 |
"parameters": {
|
| 44 |
"type": "object",
|
| 45 |
"properties": {
|
| 46 |
+
"employee_names": {"type": "array", "items": {"type": "string"}, "description": "List of employee names"}
|
|
|
|
| 47 |
},
|
| 48 |
+
"required": ["employee_names"]
|
| 49 |
}
|
| 50 |
}
|
| 51 |
],
|
|
|
|
| 56 |
if hasattr(message, "function_call") and message.function_call is not None:
|
| 57 |
try:
|
| 58 |
function_call = json.loads(message.function_call.arguments)
|
| 59 |
+
employee_names = function_call.get("employee_names", [])
|
|
|
|
| 60 |
|
| 61 |
+
results = []
|
| 62 |
+
for employee_name in employee_names:
|
| 63 |
+
sentiment = employees_data.get(employee_name)
|
| 64 |
+
if sentiment:
|
| 65 |
+
results.append(predict_attrition_risk(employee_name, sentiment))
|
| 66 |
+
else:
|
| 67 |
+
results.append(f"{employee_name}: No records found for this employee.")
|
| 68 |
+
|
| 69 |
+
return "\n".join(results)
|
| 70 |
except Exception as e:
|
| 71 |
return f"❌ Error processing LLM function call: {str(e)}"
|
| 72 |
|