llm-agent-backend/run.py
2025-11-16 23:49:12 +03:00

38 lines
1.9 KiB
Python
Raw 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.

# ----------------------------------------------- Imports ------------------------------------------------------------
import os
import sys
import atexit
import logging
# ----------------------------------------------- Logging Setup ------------------------------------------------------------
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# ----------------------------------------------- Main ------------------------------------------------------------
if __name__ == "__main__":
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app'))
from app.api import api
from app.heartbeat_monitor import HeartbeatMonitor
logger.info("🚀 Запуск LLM Agent Backend сервера...")
logger.info("📍 API будет доступно на: http://localhost:5000/api")
logger.info("📊 Список графов: http://localhost:5000/api/graphs")
logger.info("💬 Чат эндпоинт: http://localhost:5000/api/chat")
logger.info("\n⚠️ Для остановки нажмите Ctrl+C\n")
# TODO: Есть проблема с двойным запуском, скорее всего, всего приложения
# Если api.debug == True, то проверяем FLASK_RUN_FROM_RELOADER.
# Если api.debug == False, то FLASK_RUN_FROM_RELOADER, скорее всего, не будет установлен,
# и условие `not api.debug` будет True, что приведет к запуску HeartbeatMonitor.
if not api.debug or os.environ.get("FLASK_RUN_FROM_RELOADER") != "true":
heartbeat_monitor = HeartbeatMonitor(interval_minutes=5)
heartbeat_monitor.start()
atexit.register(heartbeat_monitor.stop)
logger.info("HeartbeatMonitor запущен.")
api.run(
debug=True,
port=5000,
host='localhost',
threaded=True
)