Update app.py
Browse files
app.py
CHANGED
|
@@ -68,7 +68,7 @@ def fetch_company_info(company_url):
|
|
| 68 |
logging.error(f"Exception during company info fetch: {e}")
|
| 69 |
return None
|
| 70 |
|
| 71 |
-
# Function to structure the email dynamically
|
| 72 |
def structure_email(user_data, linkedin_info, company_info):
|
| 73 |
linkedin_role = sanitize_data(linkedin_info.get('current_role', user_data['role']))
|
| 74 |
linkedin_skills = sanitize_data(linkedin_info.get('skills', 'relevant skills'))
|
|
@@ -77,6 +77,18 @@ def structure_email(user_data, linkedin_info, company_info):
|
|
| 77 |
company_mission = sanitize_data(company_info.get('mission', f"{company_name}'s mission"))
|
| 78 |
company_goal = sanitize_data(company_info.get('goal', 'achieving excellence'))
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
# Construct the email with fully sanitized and available data
|
| 81 |
email_body = (
|
| 82 |
f"Dear Hiring Manager,\n\n"
|
|
@@ -92,11 +104,11 @@ def structure_email(user_data, linkedin_info, company_info):
|
|
| 92 |
|
| 93 |
return email_body
|
| 94 |
|
| 95 |
-
# Function to validate the generated email based on critical components
|
| 96 |
def validate_email(email_content, user_data):
|
| 97 |
logging.info("Validating email content...")
|
| 98 |
|
| 99 |
-
#
|
| 100 |
required_keywords = [
|
| 101 |
user_data['name'],
|
| 102 |
user_data['role'],
|
|
@@ -105,8 +117,16 @@ def validate_email(email_content, user_data):
|
|
| 105 |
"contribute",
|
| 106 |
"Best regards"
|
| 107 |
]
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Custom Agent class following ReAct pattern
|
| 112 |
class Agent:
|
|
|
|
| 68 |
logging.error(f"Exception during company info fetch: {e}")
|
| 69 |
return None
|
| 70 |
|
| 71 |
+
# Function to structure the email dynamically with fallback for missing data
|
| 72 |
def structure_email(user_data, linkedin_info, company_info):
|
| 73 |
linkedin_role = sanitize_data(linkedin_info.get('current_role', user_data['role']))
|
| 74 |
linkedin_skills = sanitize_data(linkedin_info.get('skills', 'relevant skills'))
|
|
|
|
| 77 |
company_mission = sanitize_data(company_info.get('mission', f"{company_name}'s mission"))
|
| 78 |
company_goal = sanitize_data(company_info.get('goal', 'achieving excellence'))
|
| 79 |
|
| 80 |
+
# If essential data is missing, fill with defaults to ensure email has some content
|
| 81 |
+
if not linkedin_role:
|
| 82 |
+
linkedin_role = user_data['role']
|
| 83 |
+
if not linkedin_skills:
|
| 84 |
+
linkedin_skills = "skills relevant to this position"
|
| 85 |
+
if not linkedin_industry:
|
| 86 |
+
linkedin_industry = "the industry"
|
| 87 |
+
if not company_mission:
|
| 88 |
+
company_mission = f"{company_name}'s mission"
|
| 89 |
+
if not company_goal:
|
| 90 |
+
company_goal = "the company's goals"
|
| 91 |
+
|
| 92 |
# Construct the email with fully sanitized and available data
|
| 93 |
email_body = (
|
| 94 |
f"Dear Hiring Manager,\n\n"
|
|
|
|
| 104 |
|
| 105 |
return email_body
|
| 106 |
|
| 107 |
+
# Function to validate the generated email based on critical components with improved flexibility
|
| 108 |
def validate_email(email_content, user_data):
|
| 109 |
logging.info("Validating email content...")
|
| 110 |
|
| 111 |
+
# Basic components we want to check in the email
|
| 112 |
required_keywords = [
|
| 113 |
user_data['name'],
|
| 114 |
user_data['role'],
|
|
|
|
| 117 |
"contribute",
|
| 118 |
"Best regards"
|
| 119 |
]
|
| 120 |
+
|
| 121 |
+
# Check if the email contains all the required elements, allow some flexibility
|
| 122 |
+
missing_elements = [keyword for keyword in required_keywords if keyword.lower() not in email_content.lower()]
|
| 123 |
+
|
| 124 |
+
if missing_elements:
|
| 125 |
+
logging.info(f"Missing elements: {missing_elements}")
|
| 126 |
+
return False
|
| 127 |
+
else:
|
| 128 |
+
logging.info("Email content validation passed.")
|
| 129 |
+
return True
|
| 130 |
|
| 131 |
# Custom Agent class following ReAct pattern
|
| 132 |
class Agent:
|