Spaces:
Sleeping
Sleeping
File size: 3,578 Bytes
6a14fa9 71703c8 6a14fa9 71703c8 6a14fa9 | 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 | import requests
import json
BASE_URL = "https://mentorme666-mentorme.hf.space/api/v1"
def test_recommend():
"""Test recommend mentors endpoint"""
print("Testing Recommend Mentors...")
print("="*60)
recommendation_data = {
"goals": "Tôi muốn học Python và FastAPI để phát triển web",
"career_id": 1,
"domain_ids": [1],
"mentor_domain_ids": [2, 3],
"skill_ids": [1, 2],
"top_k": 30,
"final_count": 6
}
try:
print(f"Request URL: {BASE_URL}/recommend")
print(f"Request Data: {json.dumps(recommendation_data, indent=2, ensure_ascii=False)}")
print("\nSending request...")
response = requests.post(
f"{BASE_URL}/recommend",
json=recommendation_data,
headers={
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0",
"Accept": "application/json"
},
timeout=60
)
print(f"\n{'='*60}")
print("Response:")
print(f"{'='*60}")
print(f"Status Code: {response.status_code}")
print(f"URL: {response.url}")
if response.status_code == 200:
try:
result = response.json()
print(f"\nResponse JSON:")
print(json.dumps(result, indent=2, ensure_ascii=False))
if "mentors" in result:
print(f"\nFound {result.get('count', 0)} recommended mentors:")
for i, mentor in enumerate(result["mentors"], 1):
print(f"\n{i}. Mentor ID: {mentor.get('mentor_id')}")
print(f" Score: {mentor.get('score', 0):.4f}")
print(f" Semantic Similarity: {mentor.get('semantic_similarity', 0):.4f}")
print(f" Reason: {mentor.get('reason', 'N/A')}")
if "metadata" in mentor:
meta = mentor["metadata"]
print(f" Rating: {meta.get('rating', 'N/A')}")
if "query_text" in result:
print(f"\nQuery Text: {result['query_text']}")
print(f"\n{'='*60}")
print("[PASSED] Test completed successfully!")
return True
except json.JSONDecodeError:
print(f"Response Text: {response.text}")
print(f"\n{'='*60}")
print("[FAILED] Invalid JSON response")
return False
else:
print(f"Response Text: {response.text}")
print(f"\n{'='*60}")
print(f"[FAILED] Status code: {response.status_code}")
return False
except requests.exceptions.Timeout:
print(f"\n{'='*60}")
print("[FAILED] Request timeout")
return False
except requests.exceptions.ConnectionError as e:
print(f"\n{'='*60}")
print(f"[FAILED] Connection error: {str(e)}")
return False
except Exception as e:
print(f"\n{'='*60}")
print(f"[FAILED] Error: {str(e)}")
return False
if __name__ == "__main__":
print("\n" + "="*60)
print("MentorMe AI Service - Recommend API Test")
print("="*60 + "\n")
success = test_recommend()
print("\n" + "="*60)
if success:
print("Test Result: PASSED")
else:
print("Test Result: FAILED")
print("="*60 + "\n")
|