import os import asyncio import requests import json def test_deepseek_api_directly(): print("=== Testing DeepSeek API Directly ===") # Test 1: Direct API call to DeepSeek api_key = "sk-55f6e57f1d834b0e93ceaf98cc2cb715" base_url = "https://api.deepseek.com/v1" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Origin": "https://deepseek.com", "Referer": "https://deepseek.com/" } payload = { "model": "deepseek-chat", "messages": [ {"role": "user", "content": "Hello, how are you?"} ], "max_tokens": 50 } try: response = requests.post( f"{base_url}/chat/completions", headers=headers, json=payload, timeout=30 ) print(f"Direct API Test - Status: {response.status_code}") if response.status_code == 200: data = response.json() print("✅ DeepSeek API is working!") print(f"Response: {data['choices'][0]['message']['content']}") return True else: print(f"❌ DeepSeek API failed: {response.status_code}") print(f"Response: {response.text}") return False except Exception as e: print(f"❌ DeepSeek API error: {e}") return False def test_server_configuration(): print("\n=== Testing Server Configuration ===") # Check current environment variables print("Environment Variables:") print(f"OPENAI_API_KEY: {'*' * 20 if os.getenv('OPENAI_API_KEY') else 'NOT SET'}") print(f"OPENAI_BASE_URL: {os.getenv('OPENAI_BASE_URL', 'NOT SET')}") print(f"LLM_MODEL: {os.getenv('LLM_MODEL', 'NOT SET')}") # Test server health try: headers = {'Authorization': 'Bearer jleu1212'} response = requests.get("http://localhost:3015/health", headers=headers, timeout=10) if response.status_code == 200: data = response.json() print("✅ Server health check passed") print(f"LLM Binding: {data.get('configuration', {}).get('llm_binding')}") print(f"LLM Model: {data.get('configuration', {}).get('llm_model')}") print(f"LLM Host: {data.get('configuration', {}).get('llm_binding_host')}") return True else: print(f"❌ Server health check failed: {response.status_code}") return False except Exception as e: print(f"❌ Server health check error: {e}") return False def test_upload_endpoints(): print("\n=== Testing Upload Endpoints ===") headers = {'Authorization': 'Bearer jleu1212'} # Test available endpoints endpoints = [ "/api/documents", "/api/query", "/api/search", "/api/graph", "/upload", "/api/upload" ] for endpoint in endpoints: try: if endpoint in ["/api/query", "/api/search"]: # These are POST endpoints response = requests.post( f"http://localhost:3015{endpoint}", json={"query": "test"}, headers=headers, timeout=10 ) else: response = requests.get(f"http://localhost:3015{endpoint}", headers=headers, timeout=10) print(f"{endpoint}: {response.status_code}") if response.status_code == 404: print(f" ⚠️ Endpoint not found") elif response.status_code == 200: print(f" ✅ Endpoint working") except Exception as e: print(f"{endpoint}: Error - {e}") def check_zrun_config(): print("\n=== Checking zrun.bat Configuration ===") try: with open("LightRAG-main/zrun.bat", "r") as f: content = f.read() # Check if API key is set if "sk-55f6e57f1d834b0e93ceaf98cc2cb715" in content: print("✅ DeepSeek API key found in zrun.bat") else: print("❌ DeepSeek API key NOT found in zrun.bat") # Check if base URL is set if "https://api.deepseek.com/v1" in content: print("✅ DeepSeek base URL found in zrun.bat") else: print("❌ DeepSeek base URL NOT found in zrun.bat") # Check authentication if "AUTH_ACCOUNTS=jleu3482:jleu1212" in content: print("✅ Authentication configured in zrun.bat") else: print("❌ Authentication NOT configured in zrun.bat") except Exception as e: print(f"❌ Error reading zrun.bat: {e}") if __name__ == "__main__": print("DeepSeek API and Server Configuration Debug") print("=" * 50) # Test DeepSeek API directly api_working = test_deepseek_api_directly() # Test server configuration server_working = test_server_configuration() # Check zrun.bat configuration check_zrun_config() # Test upload endpoints test_upload_endpoints() print("\n=== Summary ===") if api_working and server_working: print("✅ DeepSeek API is working directly") print("✅ Server is running") print("⚠️ The issue is likely in the server's OpenAI client configuration") elif not api_working: print("❌ DeepSeek API is not working - check API key and regional restrictions") else: print("❌ Server configuration issue")