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"Hồ sơ Mentor: {full_name}") | |
| bio = mentor_data.get("bio", "") | |
| if bio: | |
| parts.append(f"Giới thiệu: {bio}") | |
| career = mentor_data.get("career", {}) | |
| if isinstance(career, dict) and career.get("name"): | |
| parts.append(f"Nghề nghiệp: {career['name']}") | |
| elif isinstance(career, str): | |
| parts.append(f"Nghề nghiệp: {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"Kỹ năng: {', '.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"Lĩnh vực: {', '.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 "Hiện tại" | |
| description = exp.get("description", "") | |
| exp_str = f" - {position}" | |
| if company: | |
| exp_str += f" tại {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("Kinh nghiệm làm việc:") | |
| 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" tại {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("Học vấn:") | |
| 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"Đánh giá: {rating:.1f}/5.0 ({total_ratings} đánh giá)") | |
| session_count = mentor_data.get("session_count", 0) | |
| if session_count: | |
| parts.append(f"Số buổi đã thực hiện: {session_count}") | |
| return "\n".join(parts) | |
| def build_mentee_query_text(mentee_data: Dict[str, Any]) -> str: | |
| parts = ["Đang tìm mentor để hỗ trợ về:"] | |
| goals = mentee_data.get("goals", "") | |
| if goals: | |
| parts.append(f"Mục tiêu: {goals}") | |
| career_name = mentee_data.get("career_name") | |
| career_id = mentee_data.get("career_id") | |
| if career_name: | |
| parts.append(f"Nghề nghiệp: {career_name}") | |
| elif career_id: | |
| parts.append(f"Mã nghề nghiệp: {career_id}") | |
| domain_names = mentee_data.get("domain_names", []) | |
| domain_ids = mentee_data.get("domain_ids", []) | |
| if domain_names: | |
| parts.append(f"Lĩnh vực quan tâm: {', '.join(domain_names)}") | |
| elif domain_ids: | |
| parts.append(f"Mã lĩnh vực quan tâm: {', '.join(map(str, domain_ids))}") | |
| mentor_domain_names = mentee_data.get("mentor_domain_names", []) | |
| mentor_domain_ids = mentee_data.get("mentor_domain_ids", []) | |
| if mentor_domain_names: | |
| parts.append(f"Lĩnh vực của mentor trước đây: {', '.join(mentor_domain_names)}") | |
| elif mentor_domain_ids: | |
| parts.append(f"Mã lĩnh vực của mentor trước đây: {', '.join(map(str, mentor_domain_ids))}") | |
| skill_names = mentee_data.get("skill_names", []) | |
| skill_ids = mentee_data.get("skill_ids", []) | |
| if skill_names: | |
| parts.append(f"Kỹ năng của mentor trước đây: {', '.join(skill_names)}") | |
| elif skill_ids: | |
| parts.append(f"Mã kỹ năng của mentor trước đây: {', '.join(map(str, skill_ids))}") | |
| return "\n".join(parts) | |