Files
railseek6/start_local_server_fixed.py

180 lines
5.8 KiB
Python

"""
Start LightRAG server with local-only configuration
Uses valid configuration options to avoid API dependencies
"""
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({
# Use local embeddings
"EMBEDDING_BINDING": "ollama",
# Disable reranking
"RERANK_BINDING": "null",
# Use Ollama for LLM (local)
"LLM_BINDING": "ollama",
# Set summary tokens to 0 to minimize 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", "ollama", # Use local Ollama
"--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: ollama (local)")
print(" - Embedding Binding: ollama (local)")
print(" - Rerank Binding: null (disabled)")
print(" - Entity Extraction: disabled (summary tokens: 0)")
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 upload_test_document():
"""Upload test document to the local server"""
import requests
url = "http://localhost:3017"
headers = {"X-API-Key": "jleu1212"}
test_file = "test.docx"
if not os.path.exists(test_file):
print(f"❌ Test file {test_file} not found")
return False
try:
with open(test_file, 'rb') as f:
files = {'file': (test_file, f, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')}
response = requests.post(
f"{url}/documents/upload",
files=files,
headers=headers,
timeout=30
)
if response.status_code == 200:
print("✅ Document uploaded successfully")
result = response.json()
print(f" Upload result: {result}")
return True
else:
print(f"❌ Upload failed: {response.status_code} - {response.text}")
return False
except Exception as e:
print(f"❌ Upload error: {e}")
return False
def main():
"""Main function"""
print("=" * 60)
print("🔧 LIGHTRAG LOCAL SERVER SETUP")
print("=" * 60)
# 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!")
# Upload test document
print("\n📤 Uploading test document...")
if upload_test_document():
print("\n✅ Document processing workflow completed!")
print("💡 You can now check the server logs for document processing details")
print(" and verify that bee classification appears in the processed content.")
else:
print("\n⚠️ Document upload failed, but server is running")
print("\n📝 Next steps:")
print(" 1. Check server logs for document processing details")
print(" 2. Verify bee classification appears in processed content")
print(" 3. Access Web UI at http://localhost:3017/webui")
# 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()