llm-agent-backend/run.py
2026-05-01 20:29:50 +03:00

51 lines
2.4 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__":
# Добавляем папку app в Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app'))
from app.api import api, voice_inst, current_obsidian_settings
from app.heartbeat_monitor import HeartbeatMonitor
from app.workflows import graph_history_manager
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 запущен.")
from app.heartbeat_monitor import VoiceHeartbeatMonitor
v_monitor = VoiceHeartbeatMonitor(
voice_inst,
graph_history_manager.title_generator,
lambda: current_obsidian_settings # Теперь берет настройки из api.py
)
v_monitor.start()
api.run(
debug=False, # True - тогда всё по 2 раза запускает
port=5000,
host='localhost',
threaded=True
)