Rinomina i logger per una migliore identificazione e gestisce le eccezioni nel bot di Telegram

This commit is contained in:
2025-10-13 00:31:56 +02:00
parent 3867654193
commit 01fbd5607c
4 changed files with 16 additions and 9 deletions

View File

@@ -1,4 +1,3 @@
# IMPORTANTE: Carichiamo le variabili d'ambiente PRIMA di qualsiasi altra cosa
import asyncio import asyncio
import logging import logging
from dotenv import load_dotenv from dotenv import load_dotenv
@@ -8,7 +7,6 @@ from app.agents import Pipeline
if __name__ == "__main__": if __name__ == "__main__":
# Inizializzazioni
load_dotenv() load_dotenv()
configs = AppConfig.load() configs = AppConfig.load()
@@ -23,8 +21,11 @@ if __name__ == "__main__":
telegram = TelegramApp(pipeline) telegram = TelegramApp(pipeline)
telegram.add_miniapp_url(share_url) telegram.add_miniapp_url(share_url)
telegram.run() telegram.run()
except Exception as _: except AssertionError as e:
logging.warning("Telegram bot could not be started. Continuing without it.") try:
asyncio.get_event_loop().run_forever() logging.warning(f"Telegram bot could not be started: {e}")
asyncio.get_event_loop().run_forever()
except KeyboardInterrupt:
logging.info("Shutting down due to KeyboardInterrupt")
finally: finally:
gradio.close() gradio.close()

View File

@@ -3,7 +3,7 @@ from app.agents.team import create_team_with
from app.agents.prompts import * from app.agents.prompts import *
from app.configs import AppConfig from app.configs import AppConfig
logging = logging.getLogger(__name__) logging = logging.getLogger("pipeline")
class Pipeline: class Pipeline:
@@ -30,6 +30,12 @@ class Pipeline:
""" """
self.leader_model = self.configs.models.all_models[index] self.leader_model = self.configs.models.all_models[index]
def choose_team(self, index: int):
"""
Sceglie il modello LLM da usare per il Team.
"""
self.team_model = self.configs.models.all_models[index]
def choose_strategy(self, index: int): def choose_strategy(self, index: int):
""" """
Sceglie la strategia da usare per il Predictor. Sceglie la strategia da usare per il Predictor.

View File

@@ -4,7 +4,7 @@ import time
import traceback import traceback
from typing import Any, Callable, Generic, TypeVar from typing import Any, Callable, Generic, TypeVar
logging = logging.getLogger(__name__) logging = logging.getLogger("wrapper_handler")
WrapperType = TypeVar("WrapperType") WrapperType = TypeVar("WrapperType")
WrapperClassType = TypeVar("WrapperClassType") WrapperClassType = TypeVar("WrapperClassType")
OutputType = TypeVar("OutputType") OutputType = TypeVar("OutputType")

View File

@@ -14,7 +14,7 @@ from app.configs import AppConfig
# per per_message di ConversationHandler che rompe sempre qualunque input tu metta # per per_message di ConversationHandler che rompe sempre qualunque input tu metta
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
logging = logging.getLogger(__name__) logging = logging.getLogger("telegram")
# Lo stato cambia in base al valore di ritorno delle funzioni async # Lo stato cambia in base al valore di ritorno delle funzioni async
@@ -69,7 +69,7 @@ class TelegramApp:
})} })}
httpx.post(endpoint, data=payload) httpx.post(endpoint, data=payload)
except httpx.HTTPError as e: except httpx.HTTPError as e:
logging.info(f"Failed to update mini app URL: {e}") logging.warning(f"Failed to update mini app URL: {e}")
def create_bot(self) -> None: def create_bot(self) -> None:
""" """