BasitAliii commited on
Commit
1d9aeb7
·
verified ·
1 Parent(s): adeb8fd

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +47 -0
utils.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from typing import List, Optional, Tuple
3
+ from models import Profile
4
+
5
+
6
+ def normalize_skill_list(text: Optional[str]) -> List[str]:
7
+ if not text:
8
+ return []
9
+ for sep in ["\n", ",", ";"]:
10
+ text = text.replace(sep, "|")
11
+ items = [i.strip() for i in text.split("|") if i.strip()]
12
+ return list(dict.fromkeys(items))
13
+
14
+
15
+ def make_prompt_for_matching(
16
+ current_user: Profile,
17
+ all_users: List[Profile],
18
+ top_k: int = 5,
19
+ ) -> Tuple[str, str]:
20
+ users_desc = [
21
+ {
22
+ "id": u.id,
23
+ "username": u.username,
24
+ "offers": u.offers,
25
+ "wants": u.wants,
26
+ "availability": u.availability,
27
+ "preferences": u.preferences,
28
+ }
29
+ for u in all_users
30
+ if u.id != current_user.id
31
+ ]
32
+
33
+ system = (
34
+ "You are a matchmaking assistant for a free skill-exchange platform. "
35
+ "Recommend the best matches with JSON output only."
36
+ )
37
+
38
+ user = json.dumps(
39
+ {
40
+ "current_user": current_user.to_dict(),
41
+ "candidates": users_desc,
42
+ "top_k": top_k,
43
+ },
44
+ ensure_ascii=False,
45
+ )
46
+
47
+ return system, user