DiplomovaPraca/start_servers.py
2026-05-14 12:26:11 +02:00

95 lines
2.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Запуск всех серверов для работы с графом знаний ADC.
Запускает:
1. Embedding server — localhost:8010 (локальная модель, словацкий язык)
2. LightRAG server — localhost:9621 (граф + API + WebUI)
Использование:
python start_servers.py
Остановка: Ctrl+C
"""
import subprocess
import sys
import time
import urllib.request
import os
from pathlib import Path
ROOT = Path(__file__).parent
LIGHTRAG_DIR = ROOT / "lightrag"
EMBEDDING_SCRIPT = ROOT / "embedding_server.py"
def wait_for(url, name, timeout=60):
print(f" Ожидаю {name}...", end="", flush=True)
for _ in range(timeout):
try:
urllib.request.urlopen(url, timeout=2)
print(" OK")
return True
except:
print(".", end="", flush=True)
time.sleep(1)
print(" ТАЙМАУТ")
return False
def main():
print("=" * 50)
print("Запуск серверов LightRAG ADC")
print("=" * 50)
env = os.environ.copy()
env["PYTHONUTF8"] = "1"
# 1. Embedding server
print("\n[1/2] Запуск Embedding server (порт 8010)...")
embed_proc = subprocess.Popen(
[sys.executable, str(EMBEDDING_SCRIPT)],
env=env,
cwd=str(ROOT),
)
if not wait_for("http://localhost:8010/health", "embedding server"):
print("ОШИБКА: embedding server не запустился")
embed_proc.terminate()
sys.exit(1)
# 2. LightRAG server
print("\n[2/2] Запуск LightRAG server (порт 9621)...")
lightrag_proc = subprocess.Popen(
[sys.executable, "-m", "lightrag.api.lightrag_server"],
env=env,
cwd=str(LIGHTRAG_DIR),
)
if not wait_for("http://localhost:9621/health", "LightRAG server", timeout=30):
print("ОШИБКА: LightRAG server не запустился")
embed_proc.terminate()
lightrag_proc.terminate()
sys.exit(1)
print("\n" + "=" * 50)
print("Все серверы запущены!")
print(" Embedding: http://localhost:8010/health")
print(" LightRAG: http://localhost:9621/health")
print(" WebUI: http://localhost:9621/webui (если собран)")
print("=" * 50)
print("\nCtrl+C для остановки\n")
try:
embed_proc.wait()
lightrag_proc.wait()
except KeyboardInterrupt:
print("\nОстанавливаю серверы...")
embed_proc.terminate()
lightrag_proc.terminate()
print("Готово.")
if __name__ == "__main__":
main()