llm-agent-backend/app/run.py
2026-06-06 19:29:23 +03:00

56 lines
2.6 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 ------------------------------------------------------------
# Создаем явную точку входа
def start_app():
# Добавляем папку app в Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app'))
from api import api, voice_inst, current_obsidian_settings
from heartbeat_monitor import HeartbeatMonitor
from 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 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
)
# Оставляем этот блок для локальных тестов, если запускаете исходник напрямую
if __name__ == "__main__":
start_app()