import requests import json import time def test_deepseek_search_direct(): """Test DeepSeek search functionality directly with authentication""" base_url = "http://localhost:3015" print("=== DeepSeek API Search Test ===\n") # First, let's try to login with common credentials test_credentials = [ {"username": "jleu3482", "password": "jleu1212"}, {"username": "admin", "password": "admin"}, {"username": "user", "password": "password"}, {"username": "test", "password": "test"}, ] headers = None for creds in test_credentials: print(f"Trying login with: {creds['username']}") login_data = { "username": creds["username"], "password": creds["password"] } login_response = requests.post( f"{base_url}/login", data=login_data, headers={"Content-Type": "application/x-www-form-urlencoded"} ) if login_response.status_code == 200: token = login_response.json().get("access_token") headers = {"Authorization": f"Bearer {token}"} print(f"✅ Login successful with: {creds['username']}") break else: print(f"❌ Login failed: {login_response.status_code}") if not headers: print("\n❌ Could not authenticate. Please check server authentication configuration.") return # Test search with authentication print("\n=== Testing Search with Authentication ===") search_data = { "query": "optical character recognition", "top_k": 3 } try: search_response = requests.post(f"{base_url}/search", json=search_data, headers=headers) print(f"Search response status: {search_response.status_code}") if search_response.status_code == 200: search_results = search_response.json() print("✅ Search successful!") print(f"Found {len(search_results.get('results', []))} results") for i, result in enumerate(search_results.get('results', [])): print(f"\nResult {i+1}:") print(f" Score: {result.get('score', 0):.4f}") print(f" Content: {result.get('content', '')[:200]}...") print(f" Source: {result.get('source', '')}") else: print(f"Search error: {search_response.text}") # Check if it's the DeepSeek regional error if "unsupported_country_region_territory" in search_response.text: print("\n❌ DEEPSEEK REGIONAL RESTRICTION ERROR STILL EXISTS") print("This indicates the root cause is NOT resolved") except Exception as e: print(f"Search request failed: {e}") # Test a simple query to see if DeepSeek API is working print("\n=== Testing Simple Query ===") simple_query = { "query": "test", "top_k": 1 } try: simple_response = requests.post(f"{base_url}/search", json=simple_query, headers=headers) print(f"Simple query status: {simple_response.status_code}") if simple_response.status_code == 200: print("✅ Simple query successful - DeepSeek API is working!") else: print(f"Simple query error: {simple_response.text}") except Exception as e: print(f"Simple query failed: {e}") if __name__ == "__main__": test_deepseek_search_direct()