Spaces:
Sleeping
Sleeping
| from typing import Dict, Any, List, Optional | |
| from datetime import datetime | |
| def build_mentor_text(mentor_data: Dict[str, Any]) -> str: | |
| parts = [] | |
| full_name = mentor_data.get("full_name", "") | |
| if full_name: | |
| parts.append(f"Mentor Profile: {full_name}") | |
| bio = mentor_data.get("bio", "") | |
| if bio: | |
| parts.append(f"Bio: {bio}") | |
| career = mentor_data.get("career", {}) | |
| if isinstance(career, dict) and career.get("name"): | |
| parts.append(f"Career: {career['name']}") | |
| elif isinstance(career, str): | |
| parts.append(f"Career: {career}") | |
| skills = mentor_data.get("skills", []) | |
| if skills: | |
| skill_names = [] | |
| for skill in skills: | |
| if isinstance(skill, dict): | |
| skill_names.append(skill.get("name", "")) | |
| elif isinstance(skill, str): | |
| skill_names.append(skill) | |
| if skill_names: | |
| parts.append(f"Skills: {', '.join(skill_names)}") | |
| domains = mentor_data.get("domains", []) | |
| if domains: | |
| domain_names = [] | |
| for domain in domains: | |
| if isinstance(domain, dict): | |
| domain_names.append(domain.get("name", "")) | |
| elif isinstance(domain, str): | |
| domain_names.append(domain) | |
| if domain_names: | |
| parts.append(f"Domains: {', '.join(domain_names)}") | |
| experiences = mentor_data.get("experiences", []) | |
| if experiences: | |
| exp_parts = [] | |
| for exp in experiences: | |
| if isinstance(exp, dict): | |
| position = exp.get("position", "") | |
| company = exp.get("company", "") | |
| start_date = exp.get("start_date", "") | |
| end_date = exp.get("end_date", "") or "Present" | |
| description = exp.get("description", "") | |
| exp_str = f" - {position}" | |
| if company: | |
| exp_str += f" at {company}" | |
| if start_date: | |
| exp_str += f" ({start_date} - {end_date})" | |
| if description: | |
| exp_str += f": {description}" | |
| exp_parts.append(exp_str) | |
| if exp_parts: | |
| parts.append("Experience Details:") | |
| parts.extend(exp_parts) | |
| educations = mentor_data.get("educations", []) | |
| if educations: | |
| edu_parts = [] | |
| for edu in educations: | |
| if isinstance(edu, dict): | |
| degree = edu.get("degree", "") | |
| school = edu.get("school", "") | |
| start_date = edu.get("start_date", "") | |
| end_date = edu.get("end_date", "") | |
| description = edu.get("description", "") | |
| edu_str = " -" | |
| if degree: | |
| edu_str += f" {degree}" | |
| if school: | |
| edu_str += f" from {school}" | |
| if start_date: | |
| edu_str += f" ({start_date} - {end_date})" | |
| if description: | |
| edu_str += f": {description}" | |
| edu_parts.append(edu_str) | |
| if edu_parts: | |
| parts.append("Education:") | |
| parts.extend(edu_parts) | |
| rating = mentor_data.get("rating", 0.0) | |
| total_ratings = mentor_data.get("total_ratings", 0) | |
| if rating or total_ratings: | |
| parts.append(f"Rating: {rating:.1f}/5.0 ({total_ratings} reviews)") | |
| session_count = mentor_data.get("session_count", 0) | |
| if session_count: | |
| parts.append(f"Sessions Conducted: {session_count}") | |
| return "\n".join(parts) | |
| def build_mentee_query_text(mentee_data: Dict[str, Any], resolved_names: Optional[Dict[str, Any]] = None) -> str: | |
| parts = ["Looking for mentor to help with:"] | |
| goals = mentee_data.get("goals", "") | |
| if goals: | |
| parts.append(f"Goals: {goals}") | |
| career_id = mentee_data.get("career_id") | |
| if career_id: | |
| if resolved_names and "career_name" in resolved_names: | |
| parts.append(f"Career: {resolved_names['career_name']}") | |
| else: | |
| parts.append(f"Career ID: {career_id}") | |
| domain_ids = mentee_data.get("domain_ids", []) | |
| if domain_ids: | |
| if resolved_names and "domain_names" in resolved_names and resolved_names["domain_names"]: | |
| parts.append(f"Preferred Domains: {', '.join(resolved_names['domain_names'])}") | |
| else: | |
| parts.append(f"Preferred Domains (IDs): {', '.join(map(str, domain_ids))}") | |
| mentor_domain_ids = mentee_data.get("mentor_domain_ids", []) | |
| if mentor_domain_ids: | |
| # Note: We reuse domain names mapping if available, otherwise just IDs | |
| # Ideally we would map these too if we knew they correspond to the same domain entities | |
| parts.append(f"Previous Mentor Domains (IDs): {', '.join(map(str, mentor_domain_ids))}") | |
| skill_ids = mentee_data.get("skill_ids", []) | |
| if skill_ids: | |
| if resolved_names and "skill_names" in resolved_names and resolved_names["skill_names"]: | |
| parts.append(f"Skills of Previous Mentors: {', '.join(resolved_names['skill_names'])}") | |
| else: | |
| parts.append(f"Skills of Previous Mentors (IDs): {', '.join(map(str, skill_ids))}") | |
| return "\n".join(parts) | |