Spaces:
Sleeping
Sleeping
| 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") | |