File size: 1,177 Bytes
1d9aeb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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