import json from typing import List, Optional, Tuple from models import Profile def normalize_skill_list(text: Optional[str]) -> List[str]: if not text: return [] for sep in ["\n", ",", ";"]: text = text.replace(sep, "|") items = [i.strip() for i in text.split("|") if i.strip()] return list(dict.fromkeys(items)) def make_prompt_for_matching( current_user: Profile, all_users: List[Profile], top_k: int = 5, ) -> Tuple[str, str]: users_desc = [ { "id": u.id, "username": u.username, "offers": u.offers, "wants": u.wants, "availability": u.availability, "preferences": u.preferences, } for u in all_users if u.id != current_user.id ] system = ( "You are a matchmaking assistant for a free skill-exchange platform. " "Recommend the best matches with JSON output only." ) user = json.dumps( { "current_user": current_user.to_dict(), "candidates": users_desc, "top_k": top_k, }, ensure_ascii=False, ) return system, user