-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
103 lines (78 loc) · 3.42 KB
/
python.py
File metadata and controls
103 lines (78 loc) · 3.42 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
MatchAgent API -- Python example
https://matchagent.newcool.io
Run: python examples/python.py
Requires: requests (pip install requests)
"""
import os
import requests
BASE = "https://matchagent.newcool.io"
# ---------------------------------------------------------------------------
# 1. Demo request -- no API key required
# ---------------------------------------------------------------------------
def demo_matches(user_id: int = 1, count: int = 3) -> dict:
r = requests.get(f"{BASE}/api/demo/matches/{user_id}", params={"n": count})
r.raise_for_status()
return r.json()
# ---------------------------------------------------------------------------
# 2. Production request -- pass your API key
# ---------------------------------------------------------------------------
def production_matches(user_id: int, count: int, api_key: str) -> dict:
r = requests.get(
f"{BASE}/api/v1/matches/{user_id}",
params={"n": count},
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
)
r.raise_for_status()
return r.json()
# ---------------------------------------------------------------------------
# 3. Display results
# ---------------------------------------------------------------------------
def display_match(match: dict, rank: int) -> None:
print(f"\n--- Match #{rank} (score: {match['score']}) ---")
print(f"Candidate: user {match['candidate_user_id']}")
print("\nWhy this match:")
for reason in match["explanation"]["reasons"]:
print(f" - {reason}")
print(f" Risk: {match['explanation']['risk']}")
print("\nConversation starters:")
for starter in match["explanation"]["starters"]:
print(f" > {starter}")
coach = match["coach"]["approach_style"]
print(f"\nCoach advice: {coach['label']}")
print(f" {coach['description']}")
print(f" Pace: {coach['pace']}")
print(f" Explore: {', '.join(match['coach']['topics_to_explore'])}")
print(f" Avoid: {', '.join(match['coach']['topics_to_avoid'])}")
e = match["energy"]
print("\nEnergy compatibility:")
print(f" Social: {e['social']['compatibility']} ({e['social']['score']})")
print(f" Thinking: {e['thinking']['compatibility']} ({e['thinking']['score']})")
print(f" Pace: {e['pace']['compatibility']} ({e['pace']['score']})")
print(f" Emotional: {e['emotional']['compatibility']} ({e['emotional']['score']})")
print(f" Overall: {e['overall']}")
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
def main():
print("MatchAgent API Demo")
print("===================\n")
# Demo mode
data = demo_matches(user_id=1, count=3)
profile = data["profile_summary"]
meta = data["meta"]
print(f"User: {profile['name']}, {profile['age']}, {profile['city']}")
print(f"Engine: {meta['engine']}")
print(f"Latency: {meta['latency_ms']}ms")
print(f"Signals: {', '.join(meta['signals'])}")
for i, match in enumerate(data["matches"], 1):
display_match(match, i)
# Production mode (uncomment and set your key)
# api_key = os.environ.get("MATCHAGENT_API_KEY", "ma_live_YOUR_KEY_HERE")
# prod_data = production_matches(1, 5, api_key)
# print(f"\nProduction matches: {len(prod_data['matches'])}")
if __name__ == "__main__":
main()