Files
railseek6/start_local_server.py

147 lines
4.6 KiB
Python

"""
Start LightRAG server with local-only configuration
Avoids external API dependencies for testing document processing
"""
import os
import sys
import subprocess
import time
def start_local_server():
"""Start LightRAG server with local-only configuration"""
# Environment variables for local-only operation
env = os.environ.copy()
env.update({
# Disable entity extraction to avoid API calls
"OPTIMIZE_ENTITY_EXTRACTION": "false",
"ENABLE_ENTITY_EXTRACTION": "false",
# Use local embeddings
"EMBEDDING_BINDING": "ollama",
# Disable reranking
"RERANK_BINDING": "null",
# Disable LLM for search
"LLM_BINDING": "null",
# Set summary tokens to 0 to disable entity extraction
"SUMMARY_MAX_TOKENS": "0"
})
command = [
sys.executable, "-m", "lightrag.api.lightrag_server",
"--port", "3017", # Use a different port
"--working-dir", "rag_storage",
"--input-dir", "inputs",
"--key", "jleu1212",
"--auto-scan-at-startup",
"--llm-binding", "null", # Disable LLM
"--embedding-binding", "ollama", # Use local embeddings
"--rerank-binding", "null", # Disable reranking
"--summary-max-tokens", "0" # Disable entity extraction
]
print("🚀 Starting LightRAG server with local-only configuration...")
print(f"📡 Command: {' '.join(command)}")
print("⚙️ Configuration:")
print(" - LLM Binding: null (disabled)")
print(" - Embedding Binding: ollama (local)")
print(" - Rerank Binding: null (disabled)")
print(" - Entity Extraction: disabled")
print(" - Port: 3017")
try:
process = subprocess.Popen(
command,
env=env,
cwd="LightRAG-main",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
print("⏳ Server starting...")
# Wait a bit for server to start
time.sleep(10)
# Check if process is still running
if process.poll() is None:
print("✅ Server started successfully on port 3017")
return process
else:
stdout, stderr = process.communicate()
print(f"❌ Server failed to start:")
print(f"STDOUT: {stdout}")
print(f"STDERR: {stderr}")
return None
except Exception as e:
print(f"❌ Error starting server: {e}")
return None
def test_local_server():
"""Test the local server"""
import requests
url = "http://localhost:3017"
headers = {"X-API-Key": "jleu1212"}
try:
# Test health endpoint
response = requests.get(f"{url}/", headers=headers, timeout=10)
if response.status_code == 200:
print("✅ Server health check passed")
return True
else:
print(f"❌ Server health check failed: {response.status_code}")
return False
except Exception as e:
print(f"❌ Server test error: {e}")
return False
def main():
"""Main function"""
print("=" * 60)
print("🔧 LIGHTRAG LOCAL SERVER SETUP")
print("=" * 60)
# Stop any existing servers on port 3017
try:
subprocess.run(["netstat", "-ano"], capture_output=True, text=True)
print("🛑 Checking for existing servers on port 3017...")
except:
pass
# Start the server
process = start_local_server()
if process:
print("\n" + "=" * 60)
print("🧪 TESTING LOCAL SERVER")
print("=" * 60)
# Test the server
if test_local_server():
print("\n🎉 Local server is running successfully!")
print("💡 You can now test the document processing workflow")
print(" without external API dependencies.")
print("\n📝 Next steps:")
print(" 1. Upload test.docx to http://localhost:3017/webui")
print(" 2. Check server logs for document processing details")
print(" 3. Verify bee classification appears in processed content")
# Keep the process running
try:
print("\n🔄 Server is running. Press Ctrl+C to stop.")
process.wait()
except KeyboardInterrupt:
print("\n🛑 Stopping server...")
process.terminate()
else:
print("\n❌ Server test failed")
process.terminate()
else:
print("\n❌ Failed to start server")
if __name__ == "__main__":
main()